ubuntu安裝MySql 並配置密碼
阿新 • • 發佈:2020-10-23
1.安裝
sudo apt update sudo apt install mysql-server
安裝後進不去
重啟mysql服務後成功進入
2.重啟mysql服務後登入(不需要密碼)
service mysql restar
mysql -h localhost -u root
3.修改密碼(第一次不修改了再退出 之後就登不上了)
(1)第一次嘗試
update mysql.user set password=password('root') where user='root' ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('root') where user='root'' at line 1
mysql> update mysql.user set password=password('root') where user='root' ;
然後試一下
select password from user;
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
原因是password欄位名改為authentication_string 了
(2)第二次嘗試
update mysql.user set authentication_string=password('root') where user='root' ;
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘password(‘123456’)’ at line 1
(3)又重新搜了一下,第三次嘗試
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
或者
SET PASSWORD = '123456'
4.退出後快樂重新輸入密碼進入