首次登陆修改root密码
mysql>use mysql;
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

更改用户密码
mysql>update user set authentication_string=password('new password') where user='root';

mysql>flush privileges; ###刷新权限表

GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; ###允许root用户远程登陆及访问(.的左右两边要有*号!)

编辑/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql ###数据库存储路径

socket=/var/lib/mysql/mysql.sock ###mysql.sock文件存储路径

symbolic-links=0

log-error=/var/log/mysqld.log ###mysql日志目录

pid-file=/var/run/mysqld/mysqld.pid ###mysql pid进程文件路径

character-set-server=utf8 ###mysql 设置uft8字符集
collation-server=utf8_general_ci ###mysql排序规则

validate-password=OFF ###禁用密码策略

skip-grant-tables ###跳过登陆密码,空密码登陆,使用前要把上面的validate-password=OFF项注释掉并重启mysql服务才可以

default-storage-engine=INNODB ###默认使用InnoDB存储引擎

[client]
default-character-set=utf8 ###客户端设置utf8字符集