1. 程式人生 > >LInux上MySQL的安裝

LInux上MySQL的安裝

本篇參考部落格

Linux學習之CentOS(十三)--CentOS6.4下Mysql資料庫的安裝與配置

1.myspl簡介

當在linux上進行開發的時候,無論再小的一個專案都需要資料庫。MySQL是一個關係型資料庫管理系統,由瑞典MySQL AB公司開發,目前屬於Oracle公司。MySQL是一種關聯資料庫管理系統,關聯資料庫將資料儲存在不同的表中,而不是將所有資料放在一個大倉庫內,這樣就增加了速度並提高了靈活性。MySQL的SQL語言是用於訪問資料庫的最常用標準化語言。

2.安裝過程

1.首先通過rpm -qa | grep mysql命令檢視是否安裝了mySQL資料庫。

(如果有的話可以通過rmp -e mysql 為普通刪除命令。另外還有rpm -e --nodeps mysql命令來強力解除安裝掉mysql。

2.通過yum來進行mysql的安裝。首先可以檢視可以安裝的版本

3.通過輸入 yum install -y mysql-server mysql mysql-devel 命令將mysql mysql-server mysql-devel都安裝好(注意:安裝mysql時我們並不是安裝了mysql客戶端就相當於安裝好了mysql資料庫了,我們還需要安裝mysql-server服務端才行

)

4啟動mysql 通過輸入service mysqld start 就可以開啟服務。如果是第一次啟動mysql服務,mysql伺服器會首先進行初始化。

[[email protected] ~]# service mysqld start
初始化 MySQL 資料庫: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h xiaoluo password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script![確定]
正在啟動 mysqld:                                            [確定]

當再次啟動mysql時就會有這麼多初始化了

啟動mysql之前要先啟動mysqld服務,可以通過chkconfig --list | grep mysqld 命令來檢視mysql服務是不是開機自動啟動。

我們可以看出,mysql服務並沒有開機便啟動,因此我們可以通過chkconfig mysqld on 設定其開機自啟動

mysql資料庫安裝完以後只會有一個root管理員賬號,但是此時的root賬號還並沒有為其設定密碼,在第一次啟動mysql服務時,會進行資料庫的一些初始化工作,在輸出的一大串資訊中,我們看到有這樣一行資訊 :

所以我們可以通過 該命令來給我們的root賬號設定密碼(注意:這個root賬號是mysql的root賬號,非Linux的root賬號)

此時我們就可以通過 mysql -u root -p 命令來登入我們的mysql資料庫了