經過看了幾篇文檔,都沒有寫完全。稍微整理了一下,重新一步一步進行編譯安裝mysql在centos7上。
安裝步驟如下:
1、安裝編譯環境
# yum -y install gcc- gcc-c++ ncurses-devel per |
2、建立mysql目錄和帳號,及目錄屬性
# mkdir -p /data/mydata # mkdir -p /usr/local/mysql # useradd -d /data/mydata -s /sbin/nologin -g mysql mysql # cd data/mydata/ # chown -R mysql:mysql . # cd /usr/local/mysql/ # chown -R mysql:mysql . |
3、下載copy到系統裏
# cd # ls anaconda-ks.cfg mysql-5.6.22.tar.gz |
4、解壓mysql源碼包
# tar -zxvf mysql-5.6.22.tar.g |
5、編譯mysql源碼包
說明:從mysql5.5起,mysql源碼安裝開始使用cmake了,設置源碼編譯配置腳本。
-DCMAKE_INSTALL_PREFIX=dir_name | 設置mysql安裝目錄 |
-DMYSQL_UNIX_ADDR=file_name | 設置監聽套接字路徑,這必須是一個絕對路徑名。默認爲/tmp/mysql.sock |
-DDEFAULT_CHARSET=charset_name | 設置服務器的字符集。 |
-DDEFAULT_COLLATION=collation_name | 設置服務器的排序規則。 |
-DWITH_INNOBASE_STORAGE_ENGINE=1 | 存儲引擎選項: |
-DMYSQL_DATADIR=dir_name | 設置mysql數據庫文件目錄 |
-DMYSQL_TCP_PORT=port_num | 設置mysql服務器監聽端口,默認爲3306 |
-DENABLE_DOWNLOADS=bool | 是否要下載可選的文件。例如,啓用此選項(設置爲1),cmake將下載谷歌所使用的測試套件運行單元測試。 |
# cd mysql-5.6.22 # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=mysql.mysql -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWIT H_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mydata -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 [root@localhost mysql-5.6.22]# make [root@localhost mysql-5.6.22]# make install |
6、初始化mysql數據庫
# cd scripts/ # ls mysql_install_db # ./mysql_install_db --user=mysql --datadir=/data/mydata FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db: Data::Dumper 初始化過程中會報錯,需要安裝perl-Module-Install.noarch # yum install -y perl-Module-Install.noarch # scripts/mysql_install_db --user=mysql --datadir=/data/mydata 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:
./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings |
7、複製mysql服務和啓動文件
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
|
8、開啓mysqld服務
[root@localhost ~]# service mysqld start Starting MySQL. SUCCESS! |
9、添加到chkconfig裏
[root@localhost ~]# chkconfig [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig --list iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off 檢查端口 [root@localhost ~]# netstat -tulnp | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 21466/mysqld |
10、設置環境變量PATH路徑
[root@localhost /]# vi /etc/profile -- INSERT --
PATH=/usr/local/mysql/bin:$PATH export PATH :wq "/etc/profile" # source /etc/profile |
11、進入數據庫報錯
[root@localhost /]# mysql -uroot ERROR 2002 (HY000): Can't connect to local MySQL server through socket 'mysql.mysql' (2) |
12、編輯my.cnf
[root@localhost ~]# vi /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/data/mydata port=3306 socket=/data/mydata/mysql.sock server_id=1 [mysqld_safe] log-error=/data/log/mysqld.log [mysql] socket=/data/mydata/mysql.sock [mysqldump] socket=/data/mydata/mysql.sock [mysqladmin] socket=/data/mydata/mysql.sock |
13、重啓mysqld服務
# etc/init.d/mysqld restart |
14、進入數據庫並設置密碼
# mysql –uroot mysql> set password = password('123456'); Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
|
到這裏數據庫安裝就完成了
感謝各位大拿的blog。參考鏈接
http://www.aiezu.com/db/mysql_cant_connect_through_socket.html
http://blog.csdn.net/xiagege3/article/details/41852895
http://blog.csdn.net/hengrjgc/article/details/40299213
http://wilr.iteye.com/blog/2168659
http://www.cnblogs.com/xiongpq/p/3384681.html
http://msnvip.iteye.com/blog/542004
http://blog.sina.com.cn/s/blog_637e04c9010117ri.html
http://www.cnblogs.com/fuhj02/p/3541173.html