標籤:mysql 源碼安裝
目錄
1、系統內容
2、準備使用者及資料存放區目錄
3、編譯安裝mysql
4、mysql資料庫的初始安全配置
5、mysql管理員密碼丟失的處理
1、系統內容
[[email protected]_server ~]# cat /etc/issueCentOS release 6.4 (Final)Kernel \r on an \m[[email protected]_server ~]# uname -r2.6.32-358.el6.x86_64在安裝系統時已安裝過“Development tools”及“Server Platform Development”兩個開發包組。[[email protected]_server ~]# yum -y install cmake #mysql5.5不再是make來編譯,而是採用cmake[[email protected]_server software]# pwd/root/software[[email protected]_server software]# lsmysql-5.5.36.tar.gz[[email protected]_server software]# tar xf mysql-5.5.36.tar.gz[[email protected]_server software]# lsmysql-5.5.36 mysql-5.5.36.tar.gz
如果系統內建了rpm包安裝過的mysql資料庫那先卸載:
[[email protected]_server software]# rpm -qa mysqlmysql-5.1.73-3.el6_5.x86_64[[email protected]_server software]# rpm -e --nodeps mysql
2、準備使用者及資料存放目錄
2.1、建立使用者
[[email protected]_server software]# useradd -r mysqluseradd: user ‘mysql‘ already exists #mysql使用者已存在[[email protected]_server software]# id mysqluid=27(mysql) gid=27(mysql) groups=27(mysql)
2.2、建立資料存放目錄
[[email protected]_server software]# mkdir -pv /mydata/data #在生產環境上就建立在LVM卷或存放裝置映射過來的卷上mkdir: created directory `/mydata/data‘[[email protected]_server software]# chown -R mysql.mysql /mydata/data #修改資料目錄的屬主與屬組
3、編譯安裝
[[email protected]_server software]# cd mysql-5.5.36[[email protected]_server mysql-5.5.36]# cmake . -DCMAKE_INSTALL_PREFIX=/opt/lamp/mysql55/ -DMYSQL_DATADIR=/mydata/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=ON -DWITH_ARCHIVE_STORAGE_ENGINE=ON -DWITH_BLACKHOLE_STORAGE_ENGINE=ON -DWITH_READLINE=ON -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=OFF -DDEFAULT_CHARSET=utf8 -DEXTRA=all -DDEFAULT_COLLATION=utf8_general_ci[[email protected]_server mysql-5.5.36]# make[[email protected]_server mysql-5.5.36]# make install[[email protected]_server mysql-5.5.36]# cd /opt/lamp/mysql55/[[email protected]_server mysql55]# chgrp -R mysql .[email protected]_server mysql55]# cp support-files/my-large.cnf /etc/my.cnf #提供設定檔cp: overwrite `/etc/my.cnf‘? y[[email protected]_server mysql55]# vim /etc/my.cnf #在[mysqld]欄位下加入下邊的參數datadir = /mydata/data[[email protected]_server mysql55]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld 夾 #提供服務指令碼[[email protected]_server mysql55]# chmod +x /etc/rc.d/init.d/mysqld[[email protected]_server mysql55]# ./scripts/mysql_install_db --user=mysql --datadir=/mydata/data #初始化資料庫,看見兩個“OK”就初始化成功[[email protected]_server mysql55]# ls /mydata/data #在沒有啟動mysqld服務時此目錄有以下這些檔案mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.index performance_schema test[[email protected]_server mysql55]# service mysqld start #啟動服務Starting MySQL... SUCCESS![[email protected]_server mysql55]# netstat -tnl #查看3306連接埠是否監聽[[email protected]_server mysql55]# vim /etc/profile.d/mysql.sh #匯出二進位檔案export PATH=/opt/lamp/mysql55/bin:$PATH[[email protected]_server mysql55]# source /etc/profile.d/mysql.sh[[email protected]_server mysql55]# mysql #測試能否連入mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.36-log Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>[[email protected]_server mysql55]# ls /mydata/data #啟動mysqld服務後此目錄下就會新增一些檔案db_server.err ibdata1 ib_logfile1 mysql-bin.000001 mysql-bin.000003 performance_schemadb_server.pid ib_logfile0 mysql mysql-bin.000002 mysql-bin.index test
4、mysql資料庫的初始安全配置
4.1、刪除匿名使用者
mysql> select user,host,password from mysql.user; #查看資料庫中的使用者資訊+------+------------+----------+| user | host | password |+------+------------+----------+| root | localhost | || root | db\_server | || root | 127.0.0.1 | || root | ::1 | || | localhost | || | db\_server | |+------+------------+----------+6 rows in set (0.01 sec)mysql> drop user ‘‘@‘localhost‘; #刪除一個匿名使用者mysql> drop user ‘‘@‘db\_server‘; #刪除另一個匿名使用者
如果此資料庫沒有規劃讓IPV6的地址來訪問,那可刪除root使用者以IPV6來訪問資料庫,所以如下操作:
mysql> drop user ‘root‘@‘::1‘;mysql> select user,host,password from mysql.user; #使用者刪除後的使用者資訊+------+------------+----------+| user | host | password |+------+------------+----------+| root | localhost | || root | db\_server | || root | 127.0.0.1 | |+------+------------+----------+3 rows in set (0.00 sec)
4.2、修改root使用者密碼
以上操作後只剩下‘root’使用者各三個主機名稱組合成了三種接入mysql的使用者,這三種表示對mysql來說是三個不同的使用者,如果這三個使用者的接入密碼都相同,那可直接用sql語言調用“password()”函數來統一修改user表中的“password”這個欄位的值,如下操作:
mysql> update user set password=password(‘111111‘) where user=‘root‘;Query OK, 3 rows affected (0.02 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> select user,host,password from mysql.user; #查看密碼是否修改成功+------+------------+-------------------------------------------+| user | host | password |+------+------------+-------------------------------------------+| root | localhost | *FD571203974BA9AFE270FE62151AE967ECA5E0AA || root | db\_server | *FD571203974BA9AFE270FE62151AE967ECA5E0AA || root | 127.0.0.1 | *FD571203974BA9AFE270FE62151AE967ECA5E0AA |+------+------------+-------------------------------------------+3 rows in set (0.02 sec)mysql> flush privileges; #重新整理授權表,把使用者修改後的資訊載入到記憶體中mysql> \qBye[[email protected]_server mysql55]# mysql #測試ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)[[email protected]_server mysql55]# mysql -uroot -p111111 Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.5.36-log Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
4.3、為應用程式提供專門的授權帳號
mysql的root使用者只能用於資料庫的管理,不能用於應用,比如一個php的網站程式需要與mysql互動,那應該建立一個使用者並賦予相應的許可權,專門與網站進行互動,一定不要用root使用者。
5、mysql管理員密碼丟失的處理
[[email protected]_server mysql55]# pwd/opt/lamp/mysql55[[email protected]_server mysql55]# bin/mysqld_safe --skip-grant --skip-networking & 解釋:--skip-grant #表示啟用時跳過授權表--skip-networking # 表示跳過網路,用戶端與mysqld通訊不用tcp/ip方式,即不監聽本地的3306連接埠,而只能用uninx sock方式通訊,如果不加此參數,那會監聽本地的3306連接埠,從安全的角度考慮這是不安全的。[[email protected]_server ~]# mysql #無密碼登陸mysqldWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.36-log Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> select user,host,password from mysql.user;+------+------------+-------------------------------------------+| user | host | password |+------+------------+-------------------------------------------+| root | localhost | *FD571203974BA9AFE270FE62151AE967ECA5E0AA || root | db\_server | *FD571203974BA9AFE270FE62151AE967ECA5E0AA || root | 127.0.0.1 | *FD571203974BA9AFE270FE62151AE967ECA5E0AA |+------+------------+-------------------------------------------+3 rows in set (0.01 sec)mysql> update mysql.user set password=password(‘123456‘) where user=‘root‘; #修改密碼Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed: 3 Warnings: 0[[email protected]_server ~]# service mysqld restart #重新啟動mysqlShutting down MySQL. SUCCESS!Starting MySQL.. SUCCESS![[email protected]_server ~]# mysql -uroot -p123456 #之前是的密碼是“111111”,現在已修改成了“123456”Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.36-log Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
本文出自 “知識需要總結與記錄” 部落格,請務必保留此出處http://zhaochj.blog.51cto.com/368705/1627142
CentOS 6.4 64位平台mysql5.5.36源碼編譯安裝