网站后的MySQL的基本操作

SKY RING 781 0

搭建网站后(如:wordpress,emlog,cms等)mysql简单的一些操作;

在这里我们只需要:创建数据库,用户,授权权限即可。

例子MySQL版本:mysql-5.5.54

一、登录mysql:(这里我用root登录,1.1-1.3可忽略)

mysql -uroot -p密码

(当然-p后面也可不接密码直接回车输入,这里为了安全不介意接明文显示密码)

1.1显示数据库:

show databases;

1.2选择数据库:

use 数据库名;

1.3进入数据库后显示数据库表名:

show tables;

二、新建数据库:

CREATE DATABASE 数据库名;

三、创建用户设置密码刷新权限:

创建一个本地用户并设置密码

CREATE USER 数据库用户名@localhost IDENTIFIED BY '数据库用户密码';

将某个数据库赋予某用户所有权限:

GRANT ALL PRIVILEGES ON 数据库名.* TO 数据库用户@localhost;

重载数据库权限:

FLUSH PRIVILEGES;

#下面以数据库名cvmdb,数据库用户cvmuser,密码cvmmysqlmima,为参考全例子:

[root@VM_167_186_centos ~]# mysql -uroot -p1234567890
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.54-log Source distribution
 
Copyright (c) 2000, 2016, 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> CREATE DATABASE cvmdb;
Query OK, 1 row affected (0.01 sec)
 
mysql>
mysql> CREATE USER cvmuser@localhost IDENTIFIED BY 'cvmmysqlmima';
Query OK, 0 rows affected (0.00 sec)
 
mysql>
mysql> GRANT ALL PRIVILEGES ON cvmdb.* TO cvmuser@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql>
mysql> FLUSH PRIVILEGES;
 
Query OK, 0 rows affected (0.00 sec)
 
mysql>
mysql> quit
Bye
[root@VM_167_186_centos ~]#

测试登录下新用户

[root@VM_167_186_centos ~]# mysql -ucvmuser -pcvmmysqlmima
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.5.54-log Source distribution
 
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cvmdb |
+--------------------+
2 rows in set (0.00 sec)
 
mysql> quit
Bye
[root@VM_167_186_centos ~]#

打赏
发表评论
表情 图片 链接 代码

分享
微信
微博
QQ

站点已稳定运行: | 耗时 0.244 秒 | 查询 30 次 | 内存 18.10 MB