mysql创建用户、删除用户、修改密码、授权用户和删除用户.md
程序员文章站
2022-05-16 22:27:33
...
1. 登录mysql
#1. 以root用户登录mysql服务 $ mysql -uroot -p # 输入mysql root用户密码 #2. 查看拥有哪些库,并切换到mysql库下 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cacti | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec) #3. 查看当前用户 mysql> select user,host,password from user; +-----------+---------------+-------------------------------------------+ | user | host | password | +-----------+---------------+-------------------------------------------+ | root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | | root | futeng-oracle | | | root | 127.0.0.1 | | | | localhost | | | | futeng-oracle | | | cactiuser | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | | xiaoqi | % | *777FC8D6C72FC57D2CB6F21589A3EE6F7F6D5962 | +-----------+---------------+-------------------------------------------+ 7 rows in set (0.00 sec)
2. 创建用户
未指定host则表示该用户fueng
可以在任何主机上连接该mysql服务。
mysql> create user futeng identified by '密码'; mysql> flush privileges;
指定host则表示用户只能在localhost
也就是本机访问mysql<!--EndFragment-->
CREATE USER futeng@localhost IDENTIFIED BY '密码'; flush privileges;
3. 修改密码
mysql> update user set password=password('新密码') where User="用户" and Host="位置"; #位置可指定IP、localhost或者*表示任意主机
4. 授权
#赋futeng用户在本机访问的所有权限 GRANT ALL PRIVILEGES ON *.* TO futeng@localhost; #赋远程访问的权限 GRANT ALL PRIVILEGES ON *.* TO 'futeng'@'%' WITH GRANT OPTION;
5. 删除用户
DELETE FROM user WHERE user="futeng" and host="localhost";
转载请标明作者和原文链接
ifuteng#gmail.com 2014/9/4