Linux下mysql5.7數據庫root登陸的問題

本文最後修改時間:20180313mysql

root默認爲空密碼,默認遠程沒法登陸。
mysql5.7更新了user表,網上的方法試了不少,都有點問題sql

#先中止MySQL服務
$ sudo service msyql stop安全

#跳過安全檢查
$ sudo mysqld_safe --skip-grant-tables &
若是出現以下報錯信息
mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists
解決辦法仍是很簡單的
$ sudo mkdir -p /var/run/mysqld
$ sudo chown mysql:mysql /var/run/mysqld
而後再執行
$ mysqld_safe --skip-grant-tables &socket

進入mysql
$ mysql -u root -p
#更改密碼,mysql5.7中hash的列名爲authentication_string,再也不是password了
mysql> UPDATE user SET authentication_string=PASSWORD("new password") WHERE user='root';
#容許root登陸,這裏改成容許從任意IP登陸,授予全部權限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'new password' WITH GRANT OPTION;
#刷新權限
mysql> FLUSH PRIVILEGES
#從新啓動MySQL服務
service msyql startcode

相關文章
相關標籤/搜索