mysql创建数据库、用户及导入数据

时间:2021-04-16

  1. 修改MYSQL服务器字符集为utf8:

  1.1 当前MYSQL服务器字符集设置

  SHOW VARIABLES LIKE 'character_set_%';

  1.2 修改字符集

  mysql> SET character_set_client = utf8 ;
  mysql> SET character_set_connection = utf8 ;
  mysql> SET character_set_database = utf8 ;
  mysql> SET character_set_results = utf8 ;
  mysql> SET character_set_server = utf8 ;
  mysql> SET collation_connection = utf8 ;
  mysql> SET collation_database = utf8 ;
  mysql> SET collation_server = utf8 ;

  2.创建数据库(用mysql root账号)

  2.1 create database databaseName;

  2.2 show create database databaseName;

  2.3 如果databaseName字符集不为utf8

  alter database databaseName default character set 'utf8';

  3.创建用户(用mysql root账号)

  GRANT USAGE ON *.* TO 'userName'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
  flush privileges;

  4. 授权用户

  赋予最高权限: grant all privileges on databaseName.* to userName@"localhost" identified by "123456" with grant option;
  flush privileges;

  5.初始化表

  source /xxx/xxx/dbsetup.sql

  6.初始化数据

  source /xxx/xxx/dbdata.sql

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章