net start mysql // 启动mysql服务
net stop mysql // 停止mysql服务
mysql -u root -p //登录mysql数据库
update user set password=password(”xueok654123″) where user=’root’;// 更新用户名为root的登录密码
flush privileges //刷新数据库
use dbname // 使用数据库
show databases; //显示所有数据库
show tables; //显示数据库中所有的表
describe tablename; //显示表结构
describe user; //显示数据库中user表的列信息
insert into mysql.user(Host,User,Password) values("localhost","test",password("1234")); //创建一个连接用户(此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。)
为用户授权:
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
指定所有权限给用户:
grant all privileges on testDB.* to test@localhost identified by '1234'; // test用户拥有testDB数据库的所有权限
指定部分权限给用户:
grant select,update on testDB.* to test@localhost identified by '1234'; //test用户拥有testDB数据库的查找和更新权限
指定用户拥有所有数据库的所有权限:
grant all privileges on *.* to test@"%" identified by '1234'; // test用户拥有所有数据库的所有权限(*.*为所有数据库,%表示所有ip地址都可以连接)
指定用户拥有所有数据库的部分权限:
grant select,update,delete,create,dropon *.* to test@localhost identified by '1234';
revoke privileges on databasename.tablename from 'username'@'host'; // 撤销权限
drop user 用户名@localhost; //删除用户和权限
update mysql.user set password=password('新密码') where User="test" and Host="localhost"; //修改指定用户的连接密码