MySql Linux 常用命令

MySQL 命令行操作,版本:5.6。系统环境:Linux

连接本机MySQL:mysql -u root -p

查看所有数据库:show databases;

切换到指定数据库: use 数据库;

查询MySQL用户权限:
select user,host,password from user;

删除Mysql用户权限
delete from user where user=‘root’ and host=‘localhost’;
flush privileges;

给用户赋权,允许远程机器访问
grant all privileges on . to ‘root’@’%’ identified by ‘123456’;
flush privileges;

添加指定host
GRANT ALL PRIVILEGES ON . TO ‘root’@‘localhost’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
flush privileges;

当MySQL密码无法登录解决方案:
配置文件[mysqld]下添加
skip-grant-tables
重启服务:service mysql stop; service mysql start;

登录时输入密码直接跳过,然后更新密码:
update mysql.user set password=password(‘123456’) where user=‘root’;
flush privileges;
退出将配置文件的skip-grant-tables注释掉

使用密码重新登录,再设置一次密码,如果不设置无法进行数据库操作:
SET PASSWORD = PASSWORD(‘123456’);

你可能感兴趣的:(数据库)