CentOS5.4(64bit)下安裝配置Cacti#2----Mysql安裝配置(yum安裝)

我要使用的系統版本爲:

[root@localhost ~]# cat /etc/issue

CentOS release 5.4 (Final)
Kernel \r on an \m

我使用的是yum安裝,就不要先去下載軟件了,直接用yum安裝時,就會自動下載了。

(使用yum時,還出現了一點小插曲,不過也正因爲如此才知道了更多的東西吧)。


首先是安裝Mysql

1,確認系統中是否已安裝Mysql。(CentOS好像自帶有Mysql的)

[root@localhost ~]# rpm -qa |grep mysql
mysql-5.0.77-3.el5

果然已經安裝有了,但和我要的版本不一致,升級或卸載後重新安裝。

直接更新就是了。

[root@localhost ~]# yum update mysql


2,同樣的方法確認是否有安裝mysql-server,沒有的話安裝,有的話升級。

安裝前最好查看以下具體的版本,然後選擇合適的版本安裝

[root@localhost ~]# yum list mysql*       //查詢yum源中以mysql開頭的所有包

[root@localhost ~]# yum install mysql-server.x86_64   //這是我需要的版本,安裝它


3,確認安裝完成

[root@localhost ~]# rpm -qa | grep mysql*
mysql-5.0.95-5.el5_9
mysql-server-5.0.95-5.el5_9


4,修改配置文件

[root@localhost ~]# vi /etc/my.cnf

---------------------------my.cnf中-----------------------------------------

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set=utf8   // 設置默認字符utf8

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
default-character-set=utf8   // 設置默認字符utf8

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

保存退出。


5,修改mysql服務爲系統自動啓動,同時啓動Mysql服務。

[root@localhost ~]# chkconfig mysqld on     // mysql服務爲系統自動啓動

確認以下設置成功

[root@localhost ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off    // 2~5爲on,OK。

[root@localhost ~]# service mysqld start    // 啓動Mysql服務

然後用ps命令查看系統進程中是否有mysql。

確實有,OK。


6,接下來,要配置以下Mysql的用戶,密碼等信息。

[root@localhost ~]# mysql -u root        // 用root用戶登錄mysql

mysql> select user,host,password from mysql.user ;   //查看用戶密碼
+------+-----------------------+----------+
| user | host                  | password |
+------+-----------------------+----------+
| root | localhost             |          | 
| root | localhost.localdomain |          | 
| root | 127.0.0.1             |          | 
|      | localhost             |          | 
|      | localhost.localdomain |          | 
+------+-----------------------+----------+
5 rows in set (0.00 sec)

從上可以看出,root用戶的密碼是空的,安全起見,都設下密碼吧

mysql> set password for root@localhost=password('密碼');

mysql> set password for [email protected]=password('密碼');

重新查詢,發現已經設置好了。

mysql> select user,host,password from mysql.user ;
+------+-----------------------+------------------+
| user | host                  | password         |
+------+-----------------------+------------------+
| root | localhost             | 7261bbb77f35c935 | 
| root | localhost.localdomain | 7261bbb77f35c935 | 
| root | 127.0.0.1             |                  | 
|      | localhost             |                  | 
|      | localhost.localdomain |                  | 
+------+-----------------------+------------------+
5 rows in set (0.00 sec)

後面登錄時:

[root@localhost ~]# mysql -u root -p localhost(數據庫名稱)
Enter password: 


7,上面的用戶查詢畫面有用戶名爲空的項目,需要刪除。

mysql> delete from mysql.user where user='';

Query OK, 2 rows affected (0.00 sec)

再查詢下看看,裏面就沒有用戶名爲空的項了。


這樣Mysql的安裝基本上就完成了。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章