mysql新增用户

优质老薛主机推荐:15%终身付款折扣:xwseo15 25%首次付款折扣 : xwseo115 点击下图进入购买

相信很多站长网站有很多个,那么每一个网站需要配置一个单独的数据库,这个时候就需要给mysql新增用户了,在平常我们都是用phpmyadmin来进行设置,但是有的时候我们需要在命令行来设置,现在随小魏来进行用命令行设置mysql增加用户。

新增用户分为3步骤

1.root  登陆

mysql -uroot -p

2. 查看数据库

mysql> show databases;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | mysql              |
 | performance_schema |
 | test               |
 +--------------------+
 4 rows in set (0.00 sec)

查看用户

mysql> select user,host from user;  
+------+-----------------------+  
| user | host                  |  
+------+-----------------------+  
| root | %                     |  
| root | 127.0.0.1             |  
| root | localhost             |  
| root | localhost.localdomain |  
+------+-----------------------+  
4 rows in set (0.00 sec)

3.比如我想添加一个 zabbix用户

mysql> CREATE USER 'zabbix'@'%' IDENTIFIED BY 'broadtech';
 Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'broadtech' WITH GRANT OPTION;
 Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
 Query OK, 0 rows affected (0.00 sec)

mysql>
 mysql>
 mysql> select user,host from user;
 +--------+-----------------------+
 | user   | host                  |
 +--------+-----------------------+
 | root   | %                     |
 | zabbix | %                     |
 | root   | 127.0.0.1             |
 | root   | localhost             |
 | root   | localhost.localdomain |
 +--------+-----------------------+
 5 rows in set (0.00 sec)

比如我添加lte_v1 用户

mysql> CREATE USER 'lte_v1'@'%' IDENTIFIED BY 'broadtech';  
Query OK, 0 rows affected (0.01 sec)  
  
mysql> GRANT ALL PRIVILEGES ON *.* TO 'lte_v1'@'%' IDENTIFIED BY 'broadtech' WITH GRANT OPTION;  
Query OK, 0 rows affected (0.00 sec)  
  
mysql> FLUSH PRIVILEGES;  
Query OK, 0 rows affected (0.00 sec)  
  
mysql>   
mysql> select user,host from user;  
+--------+-----------------------+  
| user   | host                  |  
+--------+-----------------------+  
| lte_v1 | %                     |  
| root   | %                     |  
| zabbix | %                     |  
| root   | 127.0.0.1             |  
| root   | localhost             |  
| root   | localhost.localdomain |  
+--------+-----------------------+  
6 rows in set (0.00 sec)

mysql新增用户

当然权限设置,通过update user 来设置

记得刷新。

赞 (0)
分享到:更多 ()