我的服务器是 Debian 8,不同的Linux发行版有一定差异。

1 下面我们来安装MySQL。

1.一条命令解决

root@Server:~# sudo apt-get install mysql-server -y

在安装过程中会要求设置root用户密码(此root非彼root)。

270_4.png

如果没有要求设置的话好像要进安全模式改。

2.安装PHP扩展

root@Server:~# sudo apt-get install php5-mysql -y

2 基础操作命令

root@Server:~# mysql -u root -p //-u 指定用户
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.5.58-0+deb8u1 (Debian)

Copyright (c) 2000, 2017, 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 |
| bbs                |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)

mysql> create database test; //新建名叫test的数据库
Query OK, 1 row affected (0.00 sec)

mysql> show databases; //查看
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> drop database test; //删除名叫test的数据库
Query OK, 0 rows affected (0.05 sec)

mysql> show databases; //查看
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql>quit; //退出
Bye
root@Server:~# mysqladmin -u root -p password "test" //修改密码,test为新密码
Enter password:
(也可以在MySQL内直接操作mysql表)

标签: MySQL

添加新评论