日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql test数据库_mysql数据库test

發布時間:2025/3/8 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql test数据库_mysql数据库test 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Re介紹一下CentOS下MySQL數據庫的安裝與配置方法

MySQL數據庫配置的具體步驟:

1、編輯MySQL的配置文件,使用vi /etc/my.cnf

[root@sample ~]# vi /etc/my.cnf  ← 編輯MySQL的配置文件

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Default to using old password format for compatibility with mysql 3.x

# clients (those using the mysqlclient10 compatibility package).

old_passwords=1  ← 找到這一行,在這一行的下面添加新的規則,讓MySQL的默認編碼為UTF-8

default-character-set = utf8  ← 添加這一行

然后在配置文件的文尾填加如下語句:

[mysql]

default-character-set = utf8

2、啟動MySQL,并讓MySQL在系統重新啟動后隨系統自動啟動。

[root@sample ~]# chkconfig mysqld on  ← 設置MySQL服務隨系統啟動自啟動

[root@sample ~]# chkconfig --list mysqld  ← 確認MySQL自啟動

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off  ← 如果2--5為on的狀態就OK

[root@sample ~]# /etc/rc.d/init.d/mysqld start  ← 啟動MySQL服務

Initializing MySQL database:         [ OK ]

Starting MySQL:              [ OK ]

3、為MySQL的root用戶設置密碼

[root@sample ~]# mysql -u root  ← 用root用戶登錄MySQL服務器

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host,password from mysql.user;  ← 查看用戶信息

+------+------------------------------+---------------+

| user | host          | password |

+------+------------------------------+---------------+

| root | localhost        |       |  ← root密碼為空

| root | sample.centospub.com  |       |  ← root密碼為空

|   | sample.centospub.com |       |

|   | localhost       |       |

+------+------------------------------+---------------+

4 rows in set (0.00 sec)

mysql> set password for root@localhost=password('在這里填入root密碼');  ← 設置root密碼

Query OK, 0 rows affected (0.01 sec)

mysql> set password for root@'sample.centospub.com'=password('在這里填入root密碼');  ← 設置root密碼

Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,password from mysql.user;  ← 查看用戶信息

+------+--------------------------------+--------------------------+

| user | host          | password     |

+------+--------------------------------+--------------------------+

| root | localhost        | 19b68057189b027f |  ← root密碼被設置

| root | sample.centospub.com   | 19b68057189b027f |  ← root密碼被設置

|    | sample.centospub.com   |          |

|    | localhost        |          |

+------+--------------------------------+--------------------------+

4 rows in set (0.01 sec)

mysql> exit  ← 退出MySQL服務器

Bye

4、測試一下root密碼有沒有生效。

[root@sample ~]# mysql -u root  ← 通過空密碼用root登錄

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  ← 出現此錯誤信息說明密碼設置成功

[root@localhost ~]# mysql -u root -h sample.centospub.com  ← 通過空密碼用root登錄

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  ← 出現此錯誤信息說明密碼設置成功

[root@sample ~]# mysql -u root -p  ← 通過密碼用root登錄

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.  ← 確認用密碼能夠成功登錄

Your MySQL connection id is 5 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit

Bye

[root@sample ~]# mysql -u root -h sample.centospub.com -p  ← 通過密碼用root登錄

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.  ← 確認用密碼能夠成功登錄

Your MySQL connection id is 6 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit  ← 退出MySQL服務器

Bye

5、刪除匿名用戶。在MySQL剛剛被安裝后,存在用戶名、密碼為空的用戶。這使得數據庫服務器有無需密碼被登錄的可能性。為消除隱患,將匿名用戶刪除。

[root@sample ~]# mysql -u root -p  ← 通過密碼用root登錄

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 7 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host from mysql.user;  ← 查看用戶信息

+------+----------------------------+

| user | host         |

+------+----------------------------+

|   | localhost       |

|   | 127.0.0.1       |

| root | localhost       |

|   | sample.centospub.com |

| root | sample.centospub.com  |

+------+----------------------------+

4 rows in set (0.02 sec)

mysql> delete from mysql.user where user='';  ← 刪除匿名用戶

Query OK, 2 rows affected (0.17 sec)

mysql> select user,host from mysql.user;  ← 查看用戶信息

+------+----------------------------+

| user | host         |

+------+----------------------------+

| root | localhost      |

| root | sample.centospub.com |

+------+----------------------------+

2 rows in set (0.00 sec)

mysql> exit  ← 退出MySQL服務器

Bye

6、刪除測試用數據庫。在MySQL被安裝后,存在名為test的空數據庫,將它刪除。這里要注意的是,系統默認的還有一個名為mysql的數據庫,它用于系統管理,所以請不要刪除。

[root@sample ~]# mysql -u root -p  ← 通過密碼用root登錄

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 8 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;  ← 查看系統已存在的數據庫

+-------------+

| Database |

+-------------+

| mysql   |

| test   |

+------------+

2 rows in set (0.02 sec)

mysql> drop database test;  ← 刪除名為test的空數據庫

Query OK, 0 rows affected (0.07 sec)

mysql> show databases;  ← 查看系統已存在的數據庫

+-------------+

| Database |

+-------------+

| mysql   |  ← 確認名為test的數據庫被刪除,已不存在

+-------------+

1 row in set (0.00 sec)

mysql> exit  ← 退出MySQL服務器

Bye

-------------------------

Re介紹一下CentOS下MySQL數據庫的安裝與配置方法

經過上面的安裝與配置,MySQL數據庫應該可以用了,下面讓我們來測一下:

1、包括建立新用戶,以及用對關系性數據庫進行數據庫操作的指令來試著建立數據庫及數據表。這里,新建用戶以centospub為例。

[root@sample ~]# mysql -u root -p  ← 通過密碼用root登錄

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all privileges on test.* to centospub@localhost identified by '在這里定義密碼';  ← 建立對test數據庫有完全操作權限的名為centospub的用戶

Query OK, 0 rows affected (0.03 sec)

mysql> select user from mysql.user where user='centospub';  ← 確認centospub用戶的存在與否

+---------+

| user  |

+---------+

| centospub |  ← 確認centospub已經被建立

+---------+

1 row in set (0.01 sec)

mysql> exit  ← 退出MySQL服務器

Bye

[root@sample ~]# mysql -u centospub -p  ← 用新建立的centospub用戶登錄MySQL服務器

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database test;  ← 建立名為test的數據庫

Query OK, 1 row affected (0.00 sec)

mysql> show databases;  ← 查看系統已存在的數據庫

+-------------+

| Database |

+-------------+

| test    |

+-------------+

1 row in set (0.00 sec)

mysql> use test  ← 連接到數據庫

Database changed

mysql> create table test(num int, name varchar(50));  ← 在數據庫中建立表

Query OK, 0 rows affected (0.03 sec)

mysql> show tables;  ← 查看數據庫中已存在的表

+-------------------+

| Tables_in_test |

+-------------------+

| test     |

+-------------------+

1 row in set (0.01 sec)

mysql> insert into test values(1,'Hello World!');  ← 插入一個值到表中

Query OK, 1 row affected (0.02 sec)

mysql> select * from test;  ← 查看數據庫中的表的信息

+------+-------------------+

| num | name      |

+------+-------------------+

| 1   | Hello World!  |

+------+-------------------+

1 row in set (0.00 sec)

mysql> update test set name='Hello Everyone!';  ← 更新表的信息,賦予新的值

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from test;  ← 查看數據庫中的表的信息

+------+----------------------+

| num | name      |

+------+----------------------+

| 1   | Hello Everyone! |  ← 確認被更新到新的值

+------+----------------------+

1 row in set (0.01 sec)

mysql> delete from test where num=1;  ← 刪除表內的值

Query OK, 1 row affected (0.00 sec)

mysql> select * from test;  ← 確認刪除結果

Empty set (0.01 sec)

mysql> drop table test;  ← 刪除表

Query OK, 0 rows affected (0.01 sec)

mysql> show tables;  ← 查看表信息

Empty set (0.00 sec)  ← 確認表已被刪除

mysql> drop database test;  ← 刪除名為test的數據庫

Query OK, 0 rows affected (0.01 sec)

mysql> show databases;  ← 查看已存在的數據庫

Empty set (0.01 sec)  ← 確認test數據庫已被刪除(這里非root用戶的關系,看不到名為mysql的數據庫)

mysql> exit  ← 退出MySQL服務器

Bye

2、刪除測試用過的遺留用戶。(當然,如果是直接建立自己的數據庫的,可以省略此步)

[root@sample ~]# mysql -u root -p  ← 通過密碼用root登錄

Enter password:  ← 在這里輸入密碼

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 12 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> revoke all privileges on *.* from centospub@localhost;  ← 取消centospub用戶對數據庫的操作權限

Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where user='centospub' and host='localhost';  ← 刪除centospub用戶

Query OK, 1 row affected (0.01 sec)

mysql> select user from mysql.user where user='centospub';  ← 查找用戶centospub,確認已刪除與否

Empty set (0.01 sec)  ← 確認centospub用戶已不存在

mysql> flush privileges;  ← 刷新,使以上操作生效

Query OK, 0 rows affected (0.01 sec)

mysql> exit

Bye

3、重新啟動一次HTTP服務,讓php-mysql反映到HTTP服務中。

[root@sample ~]# /etc/rc.d/init.d/httpd restart  ← 重新啟動HTTP服務

Stopping httpd:             [ OK ]

Starting httpd:             [ OK ]

OK了!經測試,我的網站lunfawang.com?? MySQL數據庫服務器運行正常!

-------------------------

Re介紹一下CentOS下MySQL數據庫的安裝與配置方法

感謝評分

總結

以上是生活随笔為你收集整理的mysql test数据库_mysql数据库test的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。