sudo apt-get update
sudo apt-get upgrade
# 习惯性的先设置一下时区,这里我使用东八区
date -R # 若发现时间正常则无需设置
tzselect
# 依次选择 4 -> 10 -> 1 -> 1
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date -R
# 同步时间
ntpdate ntp.aliyun.com
date -R
# 开始安装mysql
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# [mysqld] 下插入一行 写入skip-grant-tables,保存并退出,:wq!
service mysql restart
mysql -u root -p
update user set authentication_string='xxx密码xxx' where user = 'root';
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxx密码xxx';
exit
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 使用#注释掉[mysqld] 下的 skip-grant-tables,保存并退出,:wq!
service mysql restart
mysql -u root -p
# 输入你的密码
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
vim /etc/mysql/mysql.conf.d/mysqld.cnf
,在[mysqld]
下加上 skip-grant-tables
,退出并保存:wq!
systemctl restart mysql
mysql -u root
,此时无需密码use mysql;
, 选择mysql库update user set authentication_string='' where user='root';
,先清空该字段flush privileges;
,刷新权限ALTER user 'root'@'localhost' IDENTIFIED BY 'xxxxxYour Passwordxxxxxx';
,重置密码exit
,退出当前session,测试一下mysql -u root -p
,重新登录即可
若希望所有ip都可连接mysql则
```sql
select user,host,plugin from user;
update mysql.user set host='%' where user='root';
update user set authentication_string='' where user='root';
flush privileges;
ALTER user 'root'@'%' IDENTIFIED BY 'xxxxxYour Passwordxxxxxx';
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.66.1:3306’ (10061)
PS C:\Users\xxx> mysql -h 192.168.66.1 -u root -P 3306 -p
Enter password: ****
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.66.1:3306’ (10061)
vim /etc/mysql/mysql.conf.d/mysqld.cnf
,将[mysqld]
下
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
修改成:
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0