Mysql5.6.21源码安装
做了3年運維,個人筆記倒是挺多,沒有好好整理,有分享精神,比較懶,大學注冊的賬號,但是一直沒有寫過任何技術文檔,羞愧。很認同一句話,搞技術一定要有分享精神。
環境描述
安裝包:mysql-5.6.21.tar.gz
系統環境:Centos6.5
描述:安裝的系統都是最小化的方式,勾選了基礎,就下一步安裝了,因為都是實驗環境。系統配置沒有太多的要求。虛擬機。內存只分配了512Mb內存,所以大家的mysql.cnf文件,根據生產情況去分配。
(1)依賴包安裝
#yum install wget bison gcc gcc-c++ wget make cmake ncurses-devel libtool zilib-devel -y
(2)安裝包下載,為懶人提供下載連接,連接失效的自行下載。
#wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
(3)規劃好目錄,尤其生產中。別搞得亂七八糟,維護的系統都需一套統一的目錄體系結構。交接工作也一目了然。帶新人,別人也看得懂。大伙贊同吧,哈哈
#mkdir -p /data/mysqldata/{3306/{data,tmp,binlog,redo-log,undo-log},backup,scripts}
(4)創建mysql用戶,授權.
#groupadd mysql
#useradd -g mysql mysql
#chown mysql:mysql -R?/data/mysqldata
(5)解壓包,編譯安裝。
#tar zxvf mysql-5.6.21.tar.gz
#cd mysql-5.6.21
5.1:生成編譯配置文件
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='JSS for mysqltest' \
-DWITH_READLINE=ON \
-DSYSCONFDIR=/data/mysqldata/3306 \
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
5.2:編譯參數描述,這里簡單解釋下。
| DCMAKE_INSTALL_PREFIX | mysql安裝目錄,這里指的是mysql軟件的安裝路徑, |
| DDEFAULT_CHARSET | 指定mysql的字符集。 |
| DDEFAULT_COLLATION | 指定mysql服務的默認校對規則。 |
| DENABLED_LOCAL_INFILE | 是否允許從客戶端本地加載數據到Mysql服務端,專用于load data infile語句,默認不允許 |
| DWITH_*_STORAGE_ENGINE | 靜態編譯某種存儲引擎。*表示存儲引擎名稱,1表示開啟。 |
| DCOMPILATION_COMMENT | 編譯信息,后面啟動的時候會看到。 |
| DWITH_READLINE | mysql輸入輸出的處理方式 |
| DSYSCONFDIR | mysql參數文件的默認路徑 |
| DMYSQL_UNIX_ADDR | 套接字文件存儲路徑位置 |
描述:
????以上很多信息都可以安裝完成后,在my.cnf文件進行修改。如果編譯過程出錯,或者參數弄錯,可以刪除目錄下的Cmakecache.txt文件,重新執行cmake,或者重新解壓編譯即可。
5.3:執行編譯和安裝
#make?
#make install
5.4:授權,因為我是用root用戶進行安裝,但為了安全性。這部很重要啊,不要忘記了。。。
chown mysql:mysql -R?/usr/local/mysql56
(6)編輯配置文件,注意,改操作是在mysql用戶下操作。
#su - mysql
[mysql@test ~]$vim /data/mysqldata/3306/my.cnf
配置文件也規劃好,不同類別位置對方整齊。
| [client] port = 3306 binlog-ignore-db = test replicate-ignore-db = test log-slave-updates=true
|
6.1:部分參數詳解
(7)初始化數據庫。
$/usr/local/mysql56/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql56
結果如下:
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/local/mysql56/bin/mysqladmin -u root password 'new-password' ? /usr/local/mysql56/bin/mysqladmin -u root -h p_w_picpath04.com password 'new-password' Alternatively you can run: ? /usr/local/mysql56/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/local/mysql56/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 WARNING: Found existing config file /usr/local/mysql56/my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as /usr/local/mysql56/my-new.cnf, please compare it with your file and take the changes you need. |
注釋:
????看到以上結果,那么恭喜你成功了,如果報錯,或者沒有看到的同學,也不要慌張,打開日志文件/data/mysqldata/3306/mysql-error.log,查看詳情。多數原因都是因為配置文件出錯導致。找出問題后,進行修改,然后刪除/data/mysqldata/3306{data,redo,binlog}目錄下的文件,然后重新執行初始化命令即可。
????在我執行的結果看,出現了Warning,這個結果可以忽略,像我上面的結果,在初始化前,可以執行刪除配置文件,/usr/local/mysql56/my.cnf,/usr/local/mysql56/my-new.cnf,/etc/my.cnf,如果這些文件存在,可以清除掉。就發現warning消失了。
????
(8)啟動數據庫,我這里采用sale的方式啟動。
$/usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
結果如下
| [mysql@test 3306]$ /usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf & [1] 28848 [mysql@test 3306]$ 150403 19:59:32 mysqld_safe Logging to '/data/mysqldata/3306/data/../mysql-error.log'. 150403 19:59:32 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data |
8.1:查看啟動狀態
$ps -ef | grep mysql
$netstat -ano | grep 3306
[mysql@test 3306]$ ps -ef | grep mysql root ? ? 27864 ?1558 ?0 17:42 pts/0 ? ?00:00:00 su - mysql mysql ? ?27866 27864 ?0 17:42 pts/0 ? ?00:00:00 -bash mysql ? ?28848 27866 ?0 19:59 pts/0 ? ?00:00:00 /bin/sh /usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf mysql ? ?29386 28848 ?0 19:59 pts/0 ? ?00:00:00 /usr/local/mysql56/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --basedir=/usr/local/mysql56 --datadir=/data/mysqldata/3306/data --plugin-dir=/usr/local/mysql56/lib/plugin --log-error=/data/mysqldata/3306/data/../mysql-error.log --open-files-limit=512 --pid-file=/data/mysqldata/3306/mysql.pid --socket=/data/mysqldata/3306/mysql.sock --port=3306 [mysql@test 3306]$ netstat -ano | grep 3306 tcp ? ? ? ?0 ? ? ?0 :::3306 ? ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ? ? ?LISTEN ? ? ?off (0.00/0/0) unix ?2 ? ? ?[ ACC ] ? ? STREAM ? ? LISTENING ? ? 80061 ?/data/mysqldata/3306/mysql.sock |
(9)進入數據庫
注釋:默認mysql管理員賬戶是沒有設置密碼的,前面初始化后的信息,已經告訴我們怎么去設置密碼。
$/usr/local/mysql56/bin/mysql
[mysql@test 3306]$ /usr/local/mysql56/bin/mysql Welcome to the MySQL monitor. ?Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.21-log JSS for mysqltest Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (root@localhost) [(none)]>? |
(10)關閉數據庫
$ /usr/local/mysql56/bin/mysqladmin -S /data/mysqldata/3306/mysql.sock shutdown
結果如下:
[mysql@test 3306]$ /usr/local/mysql56/bin/mysqladmin -S /data/mysqldata/3306/mysql.sock shutdown 150403 21:09:30 mysqld_safe mysqld from pid file /data/mysqldata/3306/mysql.pid ended [1]+ ?Done ? ? ? ? ? ? ? ? ? ?/usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf [mysql@test 3306]$ netstat -ano | grep 3306 [mysql@test 3306]$ ps -el | grep mysql |
(11)為保障安全性,修改root用戶登錄信息
查看當前用戶信息
(root@localhost) [(none)]> select user,host from mysql.user; +------+---------------+ | user | host ? ? ? ? ?| +------+---------------+ | root | 127.0.0.1 ? ? | | root | ::1 ? ? ? ? ? | | ? ? ?| test.com ? ? ?| | root | test.com ? ? ?| | ? ? ?| localhost ? ? | | root | localhost ? ? | +------+---------------+ 6 rows in set (0.00 sec) |
刪除所有賬戶信息,只保留本地登錄
(root@localhost) [(none)]> delete from mysql.user where (user,host) not in (select 'root','localhost'); Query OK, 5 rows affected (0.00 sec) (root@localhost) [(none)]> select user,host from mysql.user; +------+-----------+ | user | host ? ? ?| +------+-----------+ | root | localhost | +------+-----------+ 1 row in set (0.00 sec) |
修改管理員賬號密碼信息
(root@localhost) [(none)]> update mysql.user set user='mysql-admin',password=password('Abcabc!23'); Query OK, 1 row affected (0.02 sec) Rows matched: 1 ?Changed: 1 ?Warnings: 0 (root@localhost) [(none)]> select user,host from mysql.user; +-------------+-----------+ | user ? ? ? ?| host ? ? ?| +-------------+-----------+ | mysql-admin | localhost | +-------------+-----------+ 1 row in set (0.00 sec) |
(12)編寫啟動,關閉,登錄腳本。
12.1:基礎信息:
$cd /data/mysqldata/script/
$vim mysql_info.ini
# set env MYSQL_USER=mysql-admin MYSQL_PASS='Abcabc!23' #check parameter if [ $# -ne 1 ] then HOST_PORT=3306 else HOST_PORT=$1 fi |
12.2:啟動腳本
$vim mysql_start.sh
#!/bin/sh #Created by jiajinh 201504 source /data/mysqldata/scripts/mysql_info.ini echo "Startup Mysql Service:localhost_"${HOST_PORT} /usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf & |
12.3:關閉腳本
$vim mysql_shutdown.sh
#!/bin/sh #Created by jiajinh 201504 source /data/mysqldata/scripts/mysql_info.ini echo "Shutdown Mysql Service:localhost_"${HOST_PORT} /usr/local/mysql56/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} -S /data/mysqldata/3306/mysql.sock shutdown |
12.4:登錄腳本
| #!/bin/sh #Created by jiajinh 201504 source /data/mysqldata/scripts/mysql_info.ini echo "Login MySQL Service:localhost_"${HOST_PORT} /usr/local/mysql56/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASS} -S /data/mysqldata/3306/mysql.sock $2 |
轉載于:https://blog.51cto.com/jiajinh/1627966
總結
以上是生活随笔為你收集整理的Mysql5.6.21源码安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: EasyUI学习笔记8:MIS开发利器_
- 下一篇: LOLS10奥恩怎么玩?山隐之焰奥恩出装