1. 程式人生 > >Linux MySQL 修改密碼

Linux MySQL 修改密碼

public variable uri 設置 visio upd pass HERE service

修改root本地登錄密碼

修改root默認的密碼(方法一)
1. 啟動mysql之後systemctl start mysqld.service
2. 修改mysql的配置文件 vi /etc/my.cnf
找到[mysqld]
skip-grant-tables
skip-networking

3. 重啟mysql systemctl restart mysqld.service
4. 重新登陸mysql 就會跳過密碼
mysql -uroot -p
5. 設置新的密碼
update mysql.user set authentication_string=password(‘123456‘) where user=‘root‘;
6. 然後刷新保存
flush privileges;
7. 退出mysql exit
再進入vi /etc/my.cnf skip-grant-tables skip-networking 刪除
8. 重啟mysql服務器 systemctl restart mysqld.service
9.再登陸就輸入新的密碼即可mysql -uroot -p

修改密碼

ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY “”

MyNewPwd123!@# 密碼需要有大寫字母 數字 和特殊字符

修改root默認的密碼(方法二)

mysql安裝完成之後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。通過下面的方式找到root默認密碼,然後登錄mysql進行修改:

shell> grep ‘temporary password‘ /var/log/mysqld.log

shell> mysql -uroot -p

mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘MyNewPass4!‘;

或者

mysql> set password for ‘root‘@‘localhost‘=password(‘MyNewPass4!‘);

記得加 grant all on *.* to ‘root‘@‘%‘ identified by ‘MyNewPass4!‘; 才可以mysqlFont遠程連接

3167錯誤

mysql> show variables like ‘%show_compatibility_56%‘;

mysql> set global show_compatibility_56=on;

1055錯誤

vim /etc/my.cnf 下面添加

sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

添加3306端口(已經添加請忽略)

firewall-cmd --zone=public --add-port=3306/tcp --permanent

重新啟動防火墻

systemctl restart firewalld.service

MySQL遠程連接:

GRANT ALL PRIVILEGES ON *.* TO ‘myuser‘@‘%‘ IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION;

Linux MySQL 修改密碼