最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在CentOS上MySQL數(shù)據(jù)庫服務器配置方法

 更新時間:2010年04月28日 21:54:38   作者:  
最近工作中經(jīng)常需要使用到MySQL,有時候在WINXP,有時候在Linux中,而這次,需要在CentOS中配置一下,還需要用到phpmyadmin, 在網(wǎng)上搜了不少的資料。
無意中還找到了CentOS的專業(yè)論壇,記住:http://www.centospub.com

于是,開始的學習配置

本次環(huán)境:

CentOS系統(tǒng),

mysql-server(版本忘了,因為是使用yum安裝的)

過程如下(轉(zhuǎn)載,根據(jù)本人安裝詳細要求,略加修改) :

 在提到網(wǎng)站構架的時候,我們經(jīng)常能夠看到“LAMP”的說法,它就是“Linux + Apache + MySQL + PHP”。 MySQL+PHP的協(xié)同成功案例已經(jīng)很多了。比如國外的PHPBB,VBB,國內(nèi)的Discuz!論壇等等程序,都是用PHP + MySQL實現(xiàn)的。和那些商務專用數(shù)據(jù)庫比起來,MySQL的功能和規(guī)??赡鼙缓枚嗳苏f的遜色一些,但對于我們個人來說,它的功能已經(jīng)算是完備。而且,通 過Discuz!官方論壇上同時在線人數(shù)的數(shù)目,也可以證明MySQL的穩(wěn)定性。

  這里,介紹一下CentOS下MySQL數(shù)據(jù)庫服務器的構建方法。 

安裝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數(shù)據(jù)庫的工具“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
  ← 找到這一行,在這一行的下面添加新的規(guī)則,讓MySQL的默認編碼為UTF-8
default-character-set = utf8  ← 添加這一行

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

[mysql]
default-character-set = utf8
啟動MySQL服務


  啟動MySQL,并讓MySQL在系統(tǒng)重新啟動后隨系統(tǒng)自動啟動。

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

[root@sample ~]# chkconfig --list mysqld  ← 確認MySQL自啟動
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off  ← 如果2--5為on的狀態(tài)就OK

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

Initializing MySQL database:         [ OK ]
Starting MySQL:              [ 
OK ]
MySQL初始環(huán)境設定


[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)  
← 出現(xiàn)此錯誤信息說明密碼設置成功

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

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

[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剛剛被安裝后,存在用戶名、密碼為空的用戶。這使得數(shù)據(jù)庫服務器有無需密碼被登錄的可能性。為消除隱患,將匿名用戶刪除。

[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] 刪除測試用數(shù)據(jù)庫

   在MySQL被安裝后,存在名為test的空數(shù)據(jù)庫,將它刪除。這里要注意的是,系統(tǒng)默認的還有一個名為mysql的數(shù)據(jù)庫,它用于系統(tǒng)管理,所以請不要刪除。

[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;  ← 查看系統(tǒng)已存在的數(shù)據(jù)庫
+-------------+
| Database |
+-------------+
| mysql   |
| test   |
+------------+
2 rows in set (0.02 sec)

mysql> drop database test;  ← 刪除名為test的空數(shù)據(jù)庫
Query OK, 0 rows affected (0.07 sec)

mysql> show databases;  ← 查看系統(tǒng)已存在的數(shù)據(jù)庫
+-------------+
| Database |
+-------------+
| mysql   |  ← 確認名為test的數(shù)據(jù)庫被刪除,已不存在
+-------------+
1 row in set (0.00 sec)

mysql> exit  ← 退出MySQL服務器
Bye
測試MySQL


  下面對MySQL進行測試。包括建立新用戶,以及用對關系性數(shù)據(jù)庫進行數(shù)據(jù)庫操作的指令來試著建立數(shù)據(jù)庫及數(shù)據(jù)表。這里,新建用戶以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數(shù)據(jù)庫有完全操作權限的名為centospub的用戶
Query OK, 0 rows affected (0.03 sec)

mysql> select user from mysql.user where user='centospub';  ← 確認centospub用戶的存在與否
+---------+
| user  |
+---------+
| centospub |  ← 確認centospub已經(jīng)被建立
+---------+
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的數(shù)據(jù)庫
Query OK, 1 row affected (0.00 sec)

mysql> show databases;  ← 查看系統(tǒng)已存在的數(shù)據(jù)庫
+-------------+
| Database |
+-------------+
| test    |
+-------------+
1 row in set (0.00 sec)

mysql> use test  ← 連接到數(shù)據(jù)庫
Database changed

mysql> create table test(num int, name varchar(50));  ← 在數(shù)據(jù)庫中建立表
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;  ← 查看數(shù)據(jù)庫中已存在的表
+-------------------+
| 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;  ← 查看數(shù)據(jù)庫中的表的信息
+------+-------------------+
| 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;  ← 查看數(shù)據(jù)庫中的表的信息
+------+----------------------+
| num | name      |
+------+----------------------+
| 1   | Hello Everyone! |  ← 確認被更新到新的值
+------+----------------------+
1 row in set (0.01 sec)

mysql> delete from test where num=1;  ← 刪除表內(nèi)的值
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的數(shù)據(jù)庫
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;  ← 查看已存在的數(shù)據(jù)庫
Empty set (0.01 sec)  ← 確認test數(shù)據(jù)庫已被刪除(這里非root用戶的關系,看不到名為mysql的數(shù)據(jù)庫)

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用戶對數(shù)據(jù)庫的操作權限
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....

相關文章

  • Mysql?InnoDB聚簇索引二級索引聯(lián)合索引特點

    Mysql?InnoDB聚簇索引二級索引聯(lián)合索引特點

    這篇文章主要為大家介紹了Mysql?InnoDB聚簇索引二級索引聯(lián)合索引特點詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • Linux安裝MySQL5.6.24使用文字說明

    Linux安裝MySQL5.6.24使用文字說明

    這篇文章主要為大家詳細介紹了Linux安裝MySQL使用文字說明,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • MySQL中的數(shù)據(jù)備份與SQL語句

    MySQL中的數(shù)據(jù)備份與SQL語句

    這篇文章主要介紹了MySQL中的數(shù)據(jù)備份與SQL語句,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • 詳解Spring Aop實現(xiàn)日志收集和重復屬性賦值

    詳解Spring Aop實現(xiàn)日志收集和重復屬性賦值

    AOP(面向切面編程)是一種編程思想,它允許開發(fā)者將公共邏輯(如日志記錄、權限校驗等)抽離出來,使得可以更專注于業(yè)務邏輯的開發(fā),SpringAOP通過定義切面、切入點、通知等概念,本文介紹Spring Aop實現(xiàn)日志收集和重復屬性賦值的相關操作,感興趣的朋友一起看看吧
    2023-04-04
  • MySQL筆記之運算符使用詳解

    MySQL筆記之運算符使用詳解

    運算符包括四類,分別是:算數(shù)運算符、比較運算符、邏輯運算符和位運算符
    2013-05-05
  • 眼見不一定為實之MySQL中的不可見字符詳解

    眼見不一定為實之MySQL中的不可見字符詳解

    這篇文章主要給大家介紹了關于眼見不一定為實之MySQL中不可見字符的相關資料,不可見字符是指在文本中無法直接顯示出來的字符,它們通常用于控制文本的格式或布局,需要的朋友可以參考下
    2024-06-06
  • MySQL 5.7忘記root密碼后修改的詳細教程

    MySQL 5.7忘記root密碼后修改的詳細教程

    因為長時間不操作mysql而忘記root密碼的朋友估計不在少數(shù),最近發(fā)現(xiàn)在MySQL 5.7版本下用之前的方法修改密碼不能成功了,所以只能重新想辦法解決,下面這篇文章主要給大家介紹了MySQL 5.7忘記root密碼后修改的詳細教程,需要的朋友可以參考。
    2017-05-05
  • SQL GROUP BY 詳解及簡單實例

    SQL GROUP BY 詳解及簡單實例

    這篇文章主要介紹了SQL GROUP BY 詳解及簡單實例的相關資料,需要的朋友可以參考下
    2017-01-01
  • MySQL中日期和時間戳互相轉(zhuǎn)換的函數(shù)和方法

    MySQL中日期和時間戳互相轉(zhuǎn)換的函數(shù)和方法

    這篇文章主要介紹了MySQL中日期和時間戳互相轉(zhuǎn)換的函數(shù)和方法,本文分別講解了時間戳轉(zhuǎn)換成日期的方法和把日期轉(zhuǎn)換為時間戳的方法,需要的朋友可以參考下
    2015-06-06
  • 安裝MySQL時,輸入mysqld --install后,顯式該文件已存在問題

    安裝MySQL時,輸入mysqld --install后,顯式該文件已存在問題

    這篇文章主要介紹了安裝MySQL時,輸入mysqld --install后,顯式該文件已存在問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12

最新評論

屯留县| 沧州市| 尼玛县| 阿瓦提县| 腾冲县| 绥芬河市| 来安县| 新河县| 嫩江县| 葵青区| 南宁市| 宽甸| 临湘市| 宜丰县| 河南省| 瑞金市| 临安市| 鄂托克前旗| 永昌县| 化隆| 正镶白旗| 乌拉特中旗| 大安市| 班玛县| 喜德县| 邵武市| 朝阳区| 东明县| 永昌县| 塔河县| 晋宁县| 高阳县| 青岛市| 商水县| 泸定县| 内丘县| 常山县| 武城县| 革吉县| 博湖县| 朝阳市|