sudo cat/etc/mysql/debian.cnf
# 下面是返回结果# Automatically generated for Debian scripts. DO NOT TOUCH![client]
host = localhost
user = debian-sys-maint
password = I7VJso2cQyIOJmq9
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = I7VJso2cQyIOJmq9
socket = /var/run/mysqld/mysqld.sock
修改密码:进入MySQLmysql -uroot -p 回车,并且执行
use mysql;# 更新 plugin 字段为 mysql 默认值:
update user set plugin='mysql_native_password';# 修改密码
alter user 'root'@'localhost' identified by 'root';# 刷新权限
flush privileges;
初始化配置
sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: N(是否设置密码验证组件,我选择否)
Please set the password for root here.
New password:(新密码)
Re-enter new password:(确认密码)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N(是否删除匿名用户,我选择否)
... skipping.
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N(不允许用户远程登录? 我选择否)
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N(删除测试数据库并访问它?我选择否)
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y(现在重新加载特权表吗?我选择是)
Success.
All done!
设置远程登录
use mysql;
update user set host='%' where user='root' and host='localhost';
GRANT ALL PRIVILEGES ON root TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root_passwd';