程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 在CentOS上MySQL數據庫辦事器設置裝備擺設辦法

在CentOS上MySQL數據庫辦事器設置裝備擺設辦法

編輯:MySQL綜合教程

在CentOS上MySQL數據庫辦事器設置裝備擺設辦法。本站提示廣大學習愛好者:(在CentOS上MySQL數據庫辦事器設置裝備擺設辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是在CentOS上MySQL數據庫辦事器設置裝備擺設辦法正文


有意中還找到了CentOS的專業服裝論壇t.vhao.net,記住:http://www.centospub.com

因而,開端的進修設置裝備擺設

本次情況:

CentOS體系,

mysql-server(版本忘了,由於是應用yum裝置的)

進程以下(轉載,依據自己裝置具體請求,略加修正) :

 在提到網站構架的時刻,我們常常可以或許看到“LAMP”的說法,它就是“Linux + Apache + MySQL + PHP”。 MySQL+PHP的協同勝利案例曾經許多了。好比國外的PHPBB,VBB,國際的Discuz!服裝論壇t.vhao.net等等法式,都是用PHP + MySQL完成的。和那些商務公用數據庫比起來,MySQL的功效和范圍能夠被很多多少人說的減色一些,但關於我們小我來講,它的功效曾經算是完整。並且,通 過Discuz!官方服裝論壇t.vhao.net上同時在耳目數的數量,也能夠證實MySQL的穩固性。

  這裡,引見一下CentOS下MySQL數據庫辦事器的構建辦法。 

裝置MySQL及相干組件


  起首,裝置MySQL。

[root@sample ~]# yum -y install mysql-server  ← 裝置MySQL

Setting up Install Process
Setting up repositories
dag 100% |=========================| 1.1 kB 00:00
update 100% |=========================| 951 B 00:00
base 100% |=========================| 1.1 kB 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 106 kB 00:00
update : ################################################## 261/261
Added 5 new packages, deleted 0 old in 2.02 seconds
Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only
Finished
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mysql-server to pack into transaction set.
mysql-server-4.1.20-1.RHE 100% |=========================| 29 kB 00:00
---> Package mysql-server.i386 0:4.1.20-1.RHEL4.1 set to be updated
--> Running transaction check
--> Processing Dependency: libmysqlclient.so.14(libmysqlclient_14) for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: mysql = 4.1.20-1.RHEL4.1 for package: mysql-server
--> Processing Dependency: libmysqlclient.so.14 for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.14(libmysqlclient_14) for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.14 for package: mysql-server
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-DBD-MySQL to pack into transaction set.
perl-DBD-MySQL-2.9004-3.1 100% |=========================| 5.4 kB 00:00
---> Package perl-DBD-MySQL.i386 0:2.9004-3.1 set to be updated
---> Downloading header for mysql to pack into transaction set.
mysql-4.1.20-1.RHEL4.1.i3 100% |=========================| 35 kB 00:00
---> Package mysql.i386 0:4.1.20-1.RHEL4.1 set to be updated
---> Downloading header for perl-DBI to pack into transaction set.
perl-DBI-1.40-8.i386.rpm 100% |=========================| 11 kB 00:00
---> Package perl-DBI.i386 0:1.40-8 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql-server i386 4.1.20-1.RHEL4.1 update 9.8 M
Installing for dependencies:
mysql i386 4.1.20-1.RHEL4.1 update 2.9 M
perl-DBD-MySQL i386 2.9004-3.1 base 111 k
perl-DBI i386 1.40-8 base 466 k

Transaction Summary
=============================================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 13 M
Downloading Packages:
(1/4): perl-DBD-MySQL-2.9 100% |=========================| 111 kB 00:00
(2/4): mysql-server-4.1.2 100% |=========================| 9.8 MB 00:11
(3/4): mysql-4.1.20-1.RHE 100% |=========================| 2.9 MB 00:03
(4/4): perl-DBI-1.40-8.i3 100% |=========================| 466 kB 00:01
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: perl-DBI ######################### [1/4]
Installing: mysql ######################### [2/4]
Installing: perl-DBD-MySQL ######################### [3/4]
Installing: mysql-server ######################### [4/4]

Installed: mysql-server.i386 0:4.1.20-1.RHEL4.1
Dependency Installed: mysql.i386 0:4.1.20-1.RHEL4.1 perl-DBD-MySQL.i386 0:2.9004-3.1 perl-DBI.i386 0:1.40-8
Complete!


  然後,裝置PHP拜訪MySQL數據庫的對象“php-mysql”。

[root@sample ~]# yum -y install php-mysql  ← 裝置php-mysql

Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only
Finished
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-mysql to pack into transaction set.
php-mysql-4.3.9-3.15.i386 100% |=========================| 18 kB 00:00
---> Package php-mysql.i386 0:4.3.9-3.15 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
php-mysql i386 4.3.9-3.15 update 35 k

Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 35 k
Downloading Packages:
(1/1): php-mysql-4.3.9-3. 100% |=========================| 35 kB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-mysql ######################### [1/1]

Installed: php-mysql.i386 0:4.3.9-3.15
Complete! 設置裝備擺設MySQL


  然後,設置裝備擺設MySQL。

[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 啟動MySQL辦事


  啟動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 ] MySQL初始情況設定


[1]為MySQL的root用戶設置暗碼

  MySQL在方才被裝置的時刻,它的root用戶是沒有被設置暗碼的。起首來設置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


   然後,測試一下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


[2] 刪除匿名用戶

  在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


[3] 刪除測試用數據庫

   在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 測試MySQL


  上面對MySQL停止測試。包含樹立新用戶,和用對關系性數據庫停止數據庫操作的指令來試著樹立數據庫及數據表。這裡,新建用戶以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


   然後,刪除測試用過的遺留用戶。

[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


  最初,從新啟動一次HTTP辦事,讓php-mysql反應到HTTP辦事中。

[root@sample ~]# /etc/rc.d/init.d/httpd restart  ← 從新啟動HTTP辦事
Stopping httpd:             [ OK ]
Starting httpd:             [ OK ]

 終究弄掂!

(*^__^*) 嘻嘻……,接上去設置裝備擺設phpmyadmin....

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved