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;