// 由于mysql5.7有弱密码限制,可以在配置文件中加上下面内容,关闭限制 // ---方法1 [mysqld] validate_password=off // ---方法2 set global validate_password_length=1; set global validate_password_policy=0;
// 查看root用户初始密码并修改root密码 grep 'temporary password' /data/mysql/error.log set password = password('your_password'); // 使用yum安装的目录有点变化 grep 'temporary password' /var/log/mysqld.log alter user 'root'@'localhost' identified by 'AAbb123@#$';
// 创建用户并授权 grant all on *.* to name@'%' identified by "password" with grant option; flush privileges;
set names utf8; 相当于: SET character_set_client = charset_name; SET character_set_results = charset_name; SET character_set_connection = charset_name;
查看数据库表的字符集设置:
1 2
show full columns from tablename; show create table [表名];
查看数据库编码:show create database [库名];
创建时指定字符集:
1 2 3 4
CREATE DATABASE [库名] DEFAULT CHARACTER SET utf8; 如果不指定默认的字符集,则系统会根据character_set_database的值进行设置 CREATE TABLE [库名].[表名] (id VARCHAR(20) NOT NULL,name VARCHAR(20) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE [库名].[表名] (id varchar(20) NOT NULL,name varchar(20) CHARACTER SET utf8 );
修改字符集:
1 2 3
ALTER DATABASE [库名] CHARACTER SET [字符集]; ALTER TABLE [表名] CHARACTER SET [字符集]; ALTER TABLE [表名] MODIFY [列名] VARCHAR(5) CHARACTER SET [字符集];