MySQL的root密码
/usr/local/mysql/bin/mysqladmin -uroot password ‘[密码]‘ 设定密码
/usr/local/mysql/bin/mysqladmin -uroot -p ‘[原密码]‘ password‘[新密码]‘ 设定密码
不知道密码的情况下,重置密码:
vi /etc/my.cnf 在[mysqld]模块增加skip-grant 表示忽略授权直接登录
重启mysql服务 /etc/init.d/mysqld restart
mysql -uroot
use mysql;
update user set password=password(‘123456‘) where user=‘root‘
mysql -u[用户名] -p[密码] -h[主机ip] -P[端口号]
mysql -u[用户名] -p[密码] -S[socket文件] 只适合本地连接
id
int(4), name
char(40));MySQL用户管理
grant all on . to ‘user1‘ identified by ‘[密码]‘; 授所有权限在所有库给user1
grant SELECT,UPDATE,INSERT on db1. to ‘user2‘@‘192.168.86.1‘ identified by ‘[密码]‘;
grant all on db1. to ‘user3‘@‘%‘ identified by ‘[密码]‘;
show grants for user2@192.168.86.1; 查看指定用户的授权信息
常用语句
select count(*) from mysql.user; 查看数据库行数(mysql是库名,user是表名)
select * from mysql.db; 显示表内容
select db from mysql.db;
select db,user from mysql.db; 显示两个字段的内容(之间用逗号隔开)
select * from mysql.db where host like ‘192.168.%‘;
insert into db1.t1 values (1, ‘abc‘); 插入内容
update db1.t1 set name=‘aaa‘ where id=1; 更新
truncate table db1.t1; 清空表的内容
drop table db1.t1; 删除表
drop database db1; 删除库
原文地址:http://blog.51cto.com/13582610/2094412