Mysql新建用户及权限设置

一:登录mysql

[root@chf chf]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 

二:创建用户

// @'%' 表示接受远程访问,若只允许本机访问,改为  @'localhost' 
mysql> create user 'youe_user'@'%' identified by 'your_passwd'; 

三:创建数据库

// 查看目前现有数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

//新建一个数据库
mysql> create database your_database; 

四:赋予用户数据库权限

// 将某个数据库的权限全部赋予某一个用户
mysql> grant all on your_databse.* to your_user@'%';
mysql> flush privileges;

你可能感兴趣的:(Mysql新建用户及权限设置)