MySql中添加用户,新建数据库,用户授权,删除用户,修改密码(注意每行后跟;表示命令语句结束):1.创建一个新用户登录MYSQL: @>mysql-uroot-p @>密码创建用户: mysql>insertintomysql.user(Host,User,Password)values("localhost","test",password("1234")); 这样就创建了一个用户名:test,密码:1234。 注意:这里的“localhost”是指用户只能在本机登录,无法在另一台机器上远程登录。如果要远程登录,将“localhost”改为“%”,即可以在任何一台电脑上登录。也可以指定某台机器可以远程登录。然后登录: mysql>退出; @>mysql-utest-p @>输入密码 mysql>登录成功2.对用户进行授权 授权格式:grantauthority在数据库上。*到用户名@由“密码”标识的登录主机; 登录MYSQL(有ROOT权限),这里以ROOT登录: @>mysql-uroot-p @>密码先为用户创建数据库(testDB): mysql>创建数据库testDB;授权测试用户拥有testDB数据库的所有权限(某数据库的所有权限): mysql>grantallprivilegesontestDB.*totest@localhostidentifiedby'1234'; mysql>flushprivileges;//刷新系统权限表 格式:grantprivilegeondatabase.*tousername@loginhostby"password"; 如果你想给一个用户分配一些权限,你可以这样写: mysql>grantselect,updateontestDB.*totest@localhostidentifiedby'1234'; mysql>刷新权限;//刷新系统权限表,授权测试用户拥有所有数据库的一定权限: mysql>grantselect,delete,update,create,dropon.测试@“%”由“1234”标识;//测试用户对所有数据库有select、delete、update、create、drop权限。 //@"%"表示授权所有非本地主机,不包括本地主机。(localhost地址设置为127.0.0.1,如果设置为真实的本地地址,不知道可不可以,也没有验证。)//授权localhost:加一句grantallprivileges在testDB.*到由“1234”标识的test@localhost;就是这样。3、删除user@>mysql-uroot-p@>passwordmysql>DeleteFROMuserWhereUser='test'andHost='localhost';mysql>flushprivileges;mysql>dropdatabasetestDB;//删除用户的数据库删除账号和权限:>dropuserusername@'%'; >dropuserusername@localhost;4、修改指定用户密码@>mysql-uroot-p@>passwordmysql>updatemysql.usersetpassword=password('newpassword')whereUser="test"andHost="localhost";mysql>flush特权;5。列出所有数据库mysql>showdatabase;6.切换数据库mysql>use'数据库名';7.列出所有表mysql>showtables;8、显示数据表结构mysql>describetablename;9、删除数据库和数据表mysql>dropdatabase数据库名;mysql>droptable数据表名;
