標籤:
一、卸載掉原有mysql
[[email protected] ~]# rpm -qa | grep mysql // 這個命令就會查看該作業系統上是否已經安裝了mysql資料庫
有的話,我們就通過 rpm -e 命令 或者 rpm -e --nodeps 命令來卸載掉
[[email protected] ~]# rpm -e mysql // 普通刪除模式[[email protected] ~]# rpm -e --nodeps mysql // 強力刪除模式,如果使用上面命令刪除時,提示有依賴的其它檔案,則用該命令可以對其進行強力刪除
在刪除完以後我們可以通過 rpm -qa | grep mysql 命令來查看mysql是否已經卸載成功!!
三、通過yum來進行mysql的安裝
我是通過yum的方式來進行mysql的資料庫安裝,首先我們可以輸入 yum list | grep mysql 命令來查看yum上提供的mysql資料庫可下載的版本:
[[email protected] ~]# yum list | grep mysql
就可以得到yum伺服器上mysql資料庫的可下載版本資訊:
然後我們可以通過輸入 yum install -y mysql-server mysql mysql-devel 命令將mysql mysql-server mysql-devel都安裝好(注意:安裝mysql時我們並不是安裝了mysql用戶端就相當於安裝好了mysql資料庫了,我們還需要安裝mysql-server服務端才行)
[[email protected] ~]# yum install -y mysql-server mysql mysql-deve
在等待了一番時間後,yum會幫我們選擇好安裝mysql資料庫所需要的軟體以及其它附屬的一些軟體
我們發現,通過yum方式安裝mysql資料庫省去了很多沒必要的麻煩,當出現下面的結果時,就代表mysql資料庫安裝成功了
此時我們可以通過如下命令,查看剛安裝好的mysql-server的版本
[[email protected] ~]# rpm -qi mysql-server
我們安裝的mysql-server並不是最新版本,如果你想嘗試最新版本,那就去mysql官網下載rpm包安裝就行了,至此我們的mysql資料庫已經安裝完成了。
四、mysql資料庫的初始化及相關配置
我們在安裝完mysql資料庫以後,會發現會多出一個mysqld的服務,這個就是咱們的資料庫服務,我們通過輸入service mysqld start 命令就可以啟動我們的mysql服務。
注意:如果我們是第一次啟動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 % compatiblewith this binary MySQL version. The MySQL daemon, mysqld, should worknormally with the exception that host name resolving will not work.This means that you should use IP addresses instead of hostnameswhen specifying MySQL privileges !Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE 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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly 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.plcd /usr/mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script! [確定]正在啟動 mysqld: [確定]
這時我們會看到第一次啟動mysql伺服器以後會提示非常多的資訊,目的就是對mysql資料庫進行初始化操作,當我們再次重新啟動mysql服務時,就不會提示這麼多資訊了,如:
[[email protected] ~]# service mysqld restart停止 mysqld: [確定]正在啟動 mysqld: [確定]
我們在使用mysql資料庫時,都得首先啟動mysqld服務,我們可以 通過 chkconfig --list | grep mysqld 命令來查看mysql服務是不是開機自動啟動,如:
[[email protected] ~]# chkconfig --list | grep mysqldmysqld 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
我們發現mysqld服務並沒有開機自動啟動,我們當然可以通過 chkconfig mysqld on 命令來將其設定成開機啟動,這樣就不用每次都去手動啟動了
[[email protected] ~]# chkconfig mysqld on[[email protected] ~]# chkconfig --list | grep mysqlmysqld 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
mysql資料庫安裝完以後只會有一個root管理員帳號,但是此時的root帳號還並沒有為其設定密碼,在第一次啟動mysql服務時,會進行資料庫的一些初始化工作,在輸出的一大串資訊中,我們看到有這樣一行資訊 :
/usr/bin/mysqladmin -u root password ‘new-password‘ // 為root帳號設定密碼
所以我們可以通過 該命令來給我們的root帳號設定密碼(注意:這個root帳號是mysql的root帳號,非Linux的root帳號)
[[email protected] ~]# mysqladmin -u root password ‘root‘ // 通過該命令給root帳號設定密碼為 root
此時我們就可以通過 mysql -u root -p 命令來登入我們的mysql資料庫了
二,遠端存取設定
修改MySQL的root使用者的密碼以及開啟遠端連線
[[email protected] mysql]# mysql -u root mysql
mysql> use mysql;
mysql> desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]"%" IDENTIFIED BY "root"; //為root添加遠端連線的能力
mysql> update user set Password = password(‘123456‘) where User=‘root‘; //設定root使用者密碼
mysql> select Host,User,Password from user where User=‘root‘;
mysql> flush privileges;
mysql> exit
centos6.5下安裝mysql