1.忽略大小写安装:
方案是:1.先安装;2.修改配置文件,添加lower_case_table_names=1,备份该配置文件;3.卸载mysql;4.保留修改后的配置文件的情况下重装mysql;
具体命令:
apt-get install mysql-server
cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.backup
service mysql stop
apt-get --purge autoremove mysql-server
rm -R /var/lib/mysql
cp /etc/mysql/mysql.conf.d/mysqld.cnf.backup /etc/mysql/mysql.conf.d/mysqld.cnf
vim /etc/mysql/mysql.conf.d/mysqld.cnf
...
lower_case_table_names=1
...
apt-get install mysql-server
service mysql start
mysql_secure_installation
2.修改密码:
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
FLUSH PRIVILEGES;
三:root无需密码,或任何密码都可以登录原因及解决方法
虽然改了密码,但是发现root登录仍无需登录密码,或者加参数-p输入密码时,任何密码都可以进入。
原因:查看用户插件信息
select user,host,plugin from mysql.user;
显示root插件为auth_socket,这种插件无需密码,所以设置任何密码都无效。
mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| debian-sys-maint | localhost | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | auth_socket |
+------------------+-----------+-----------------------+
5 rows in set (0.00 sec)
更改插件为mysql_native_password 或者caching_sha2_password
use mysql;
UPDATE user SET plugin='caching_sha2_password' WHERE User='root';
FLUSH PRIVILEGES;
更改完成后,需重新设置root密码生效,修改方法同上。修改后,登录需要输入正确密码