mysql 忘記了root密碼,以無密碼的root進入,
mysql -uroot -p '直接回車進入,這時候的root是沒有任何權限的。
exit '退出mysql
關閉mysql
service --status-all '查看安裝的mysql服務是mysql還是mysqld
service mysql/mysqld stop
跳過表格的權限,直接在shell裏面執行
mysqld_safe --skip-grant-tables
啓動mysql
service mysql/mysqld start
以無密碼進入mysql
mysql -uroot -p '直接回車進入,這時候的root是沒有任何權限的。
查看mysql的用戶表
use mysql;
select Host,User,Password from user;
這時候就可以查看到mysql裏面部分用戶名和密碼了,包括root@localhost的。
若在執行grant語法的時候出現 ‘The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement’
flush privileges;
這樣就解決了。
mysql創建新的用戶
mysql -u root -p '進入mysql
insert into mysql.user(Host,User,Password) values("localhost","username",password("1234")); '新建用戶
flush privileges; ‘刷新權限表
mysql更改root密碼
UPDATE user SET Password=PASSWORD(‘newpassword’) where USER=‘root’;
flush privileges;
創建數據庫
create database databasename;
爲數據庫賦予該數據庫的所有權限
grant all privileges on databasename.* to username@'localhost' identified by 'password';
若出現Can't find any matching row in the user table
flush privileges;