mysql5.6 linux 安装设置密码和远程登录

mysql 设置跳过登陆验证:

vim /etc/my.cnf文件;
在[mysqld]后添加skip-grant-tables(登录时跳过权限检查)

[mysqld]
skip-grant-tables
port        = 3306
socket        = /tmp/mysql.sock
datadir = /www/server/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K

重启systemctl restart mysqld

mysql 设置密码:

登录mysql,输入mysql -h localhost -u root -P 3306 -p;直接回车(Enter)


use mysql;

set password for 'root'@'localhost'=password('1234!@#$qwerQWER');

如果报:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
输入:
flush privileges;
再输入:
set password for 'root'@'localhost'=password('1234!@#$qwerQWER');

flush privileges;

mysql 设置远程登录:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '1234!@#$qwerQWER' WITH GRANT OPTION;

flush privileges;

再把my.ini的skip-grant-tables删除或者注释掉

重启MySQL:sudo systemctl restart mysqld
再次连接,成功