MySQL创建数据库相关命令
1.数据库创建
第⼀步:登录数据库,输⼊命令sudo mysql -u root -p
[f /home/loongshawn]
$sudo mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[f /home/loongshawn]
$sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 41892
Server version: 5.6.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
下载mysql服务端命令and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
mysql>
第⼆步:登录数据库,查看当前已存在数据库,并创建创建数据库。
mysql> show databases;
+--------------------+
| Database          |
+--------------------+
| information_schema |
| data_loong_1      |
| data_loong_2      |
| mapdata_1          |
| mapdata_2          |
| mysql              |
| performance_schema |
| rong_1            |
| rong_2            |
| test              |
+--------------------+
10 rows in set (0.02 sec)
创建数据库命令create database knowledge_base_daily;
mysql> create database knowledge_base_daily;
Query OK, 1 row affected (0.00 sec)
2.分配权限
给数据库分配⽤户、分配权限,由于库中已存在⽤户,就不再新建⽤户及权限了,然后manager这个⽤户拥有数据库的所有权限;
mysql> grant all privileges on knowledge_base_daily.* to 'manager'@'%' identified by '12345678';
Query OK, 0 rows affected (0.08 sec)
mysql> grant all privileges on knowledge_base_publish.* to 'manager'@'%' identified by '12345678';
Query OK, 0 rows affected (0.00 sec)
mysql>
如果需要给具体⽤户分配数据库具体数据表的权限,使⽤以下命令,如manager拥有table的update权限。
grant update on knowledge_base_publish.table to 'manager'@'%';
补充说明如何新建⽤户,通过命令:
create user 'loongshawn'@'%' identified by '12345678';
Query OK, 0 rows affected (0.08 sec)
3.补充说明
若⽂中有不详尽之处,请留⾔或⾃⾏去百度搜索。欢迎讨论。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。