一、数据库的连接
1:连接本地数据库(root 用户,隐藏密码)
mysql -u root -p
2:连接本地数据库(root用户,密码为123,与-p不能有空格)
mysql -u root -p123
3:远程连接数据库(IP为192.168.7.116,用户为ll)
mysql -h 192.168.7.116 -P 3306 -u ll -p
4:连接指定的数据库Test(登陆进去可直接用select database()查看)
mysql -u root -p123 -D Test
二、密码的修改
1:在没有密码的情况下
mysqladmin -u root password
2:修改密码(在知道原密码的情况下)
mysqladmin -u root -p password 123
3:在mysql.user表里修改(重启mysql服务或flush privileges才生效,password设置的时候不能直接password='13')
update mysql.user set password=password('123456') where user='root' and host='localhost';
4:在mysql里修改:
set password for ll=password('123456');
5:忘记密码
打开配置文件 vim /etc/my.cnf 在里面添加 skip-grant-tables
三、用户添加与授权
1:create添加用户
create user ll identified by '123456';
2:修改用户名
rename user ll to lll;
3:在mysql的user表中直接添加用户信息
insert into mysql.user(User,Host,Password) values('ll','localhost',password('123'));
3: grant授权方式添加用户
grant select,insert on lop.* to 'mm'@'localhost' identified by '123';
若密码修改为空
grant select,insert on lop.* to 'mm'@'localhost' identified by '';
4:查看用户的权限
show grants ; show grants for ll;
5:权限的收回
revoke select,insert on lop.* from 'mm'@'localhost';
四、删除用户
1:在mysql的user表中删除
delete from mysql.user where user='ll';
drop user 'll'@'localhost'