部署環境html
操做系統:CentOS-6.6-x86_64-bin-DVD1.isomysql
MySQL版本:mysql-5.6.26.tar.gz linux
操做用戶:rootc++
系統IP:192.168.1.205web
主機名:edu-mysql-01sql
配置:4核、4G內存 數據庫
一、配置網絡安全
# vi /etc/sysconfig/network-scripts/ifcfg-eth0服務器
DEVICE=eth0網絡
BOOTPROTO=static
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
HWADDR=00:50:56:a1:12:53
IPADDR=192.168.1.205
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=223.5.5.5
DNS2=223.6.6.6
二、設置主機名
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=edu-mysql-01
三、設置IP與主機名的映射
# vi /etc/hosts
127.0.0.1 edu-mysql-01
192.168.1.205 edu-mysql-01
四、兩臺數據庫服務器的的selinux都要disable
(永久關閉selinux,請修改/etc/selinux/config,將SELINUX改成disabled)
# vi /etc/selinux/config
SELINUX=disabled
五、重啓操做系統
# reboot
2、源碼安裝MySQL5.6.26:
1、使用下面的命令檢查是否安裝有MySQL Server:
# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
若是是CentOS7以上,請使用如下命令查看:
# rpm -qa | grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
(由於沒有MySQL服務,所以不必卸載。mysql-libs是MySQL的必要包)
(若是有的話可經過下面的命令來卸載掉,rpm -e mysql //普通刪除模式)
二、改防火牆設置,打開3306端口:
# vi /etc/sysconfig/iptables
增長以下行:
## MySQL
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
重啓防火牆:
# service iptables restart
三、新增mysql用戶組:
# groupadd mysql
四、新增mysql用戶,並添加到mysql用戶組:
# useradd -r -g mysql mysql
五、新建MySQL執行文件目錄(後面會把編譯好的mysql程序安裝到這個目錄):
# mkdir -p /usr/local/mysql
(-p 參數的做用是:若是最終目錄的父目錄不存在也會一併建立)
六、新建MySQL數據庫數據文件目錄:
# mkdir -p /home/mysql/data
# mkdir -p /home/mysql/logs
# mkdir -p /home/mysql/temp
(注意:上面的logs及temp目錄是爲了之後將MySQL的數據文件與執行程序文件分離,若是你打算設置到不一樣的路徑,注意修改對應的執行命令和數據庫初始化腳本。正式生產環境,建議數據目錄和日誌目錄都使用單獨的分區來掛載,不一樣分區屬於不一樣的磁盤或磁盤組。)
七、增長PATH環境變量搜索路徑:
# vi /etc/profile
##在profile文件末尾增長兩行
# mysql env param
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
使PATH搜索路徑當即生效:
# source /etc/profile
八、安裝編譯MySQL須要的依賴包:
(mysql從5.5版本開始,再也不使用./configure編譯,而是使用cmake編譯器,具體的cmake編譯參數能夠參考mysql官網文檔
http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html,安裝基本依賴包,先用yum安裝cmake、automake 、autoconf ,另MySQL 5.5.x須要最少安裝的包有:bison,gcc、gcc-c++、ncurses-devel):
# yum install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-devel autoconf automake
九、進入/usr/local/src目錄,上傳mysql-5.6.26.tar.gz源代碼到/usr/local/src目錄:
# cd /usr/local/src
十、開始編譯安裝mysql-5.6.26:
解壓縮源碼包:
# tar -zxvf mysql-5.6.26.tar.gz
進入解壓縮源碼目錄:
# cd mysql-5.6.26
使用cmake源碼安裝mysql(若是你打算安裝到不一樣的路徑,注意修改下面語句中/usr/local/mysql和/home/mysql/data路徑!)
[root@edu-mysql-01 mysql-5.6.26]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/home/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
上面的這些複製完,回車,而後就開始cmake的過程,通常時間不會很長。
配置解釋:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 設置安裝目錄
-DMYSQL_DATADIR=/home/mysql/data 設置數據庫存放目錄
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 設置UNIX socket 目錄
-DMYSQL_USER=mysql 設置運行用戶
-DDEFAULT_CHARSET=utf8 設置默認字符集,默認latin1
-DEFAULT_COLLATION=utf8_general_ci 設置默認校對規則,默認latin1_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1 添加InnoDB引擎支持
-DENABLE_DOWNLOADS=1 自動下載可選文件,好比自動下載谷歌的測試包
-DMYSQL_TCP_PORT=3306 設置服務器監聽端口,默認3306
-DSYSCONFDIR=/etc 設置my.cnf所在目錄,默認爲安裝目錄)
執行過程當中會出現:
CMake Error: Problem with tar_extract_all(): Invalid argument
CMake Error: Problem extracting tar: /usr/local/src/mysql-5.6.26/source_downloads/gmock-1.6.0.zip
解決方法:
cd mysql目錄下面會發現有一個source_downloads目錄,須要解壓unzip gmock-1.6.0.zip,而後再從新執行上述配置過程。固然你也能夠去掉-DENABLE_DOWNLOADS=1這個選項,不編譯谷歌的測試包也沒有什麼問題,可是以前的某些版本會出現沒法編譯的問題.
十一、cmake結束後開始編譯源碼,這一步時間會較長,請耐心等待:
# make
十二、安裝編譯好的程序:
# make install
(注意:若是須要重裝mysql,在/usr/local/src/mysql-5.6.26在執行下make install就能夠了,不須要再cmake和make)
1三、清除安裝臨時文件:
# make clean
1四、修改mysql目錄擁有者爲mysql用戶:
# chown -Rf mysql:mysql /usr/local/mysql
# chown -Rf mysql:mysql /home/mysql
1五、進入mysql執行程序的安裝路徑:
# cd /usr/local/mysql
1六、執行初始化配置腳本,建立系統自帶的數據庫和表(注意:路徑/home/mysql/data須要換成你自定定義的數據庫存放路徑):
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
Installing MySQL system tables...2015-12-13 15:21:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-13 15:21:53 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.26) starting as process 17362 ...
2015-12-13 15:21:53 17362 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-12-13 15:21:53 17362 [Note] InnoDB: The InnoDB memory heap is disabled
2015-12-13 15:21:53 17362 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-12-13 15:21:53 17362 [Note] InnoDB: Memory barrier is not used
2015-12-13 15:21:53 17362 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-12-13 15:21:53 17362 [Note] InnoDB: Using CPU crc32 instructions
2015-12-13 15:21:53 17362 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-12-13 15:21:53 17362 [Note] InnoDB: Completed initialization of buffer pool
2015-12-13 15:21:53 17362 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-12-13 15:21:53 17362 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-12-13 15:21:53 17362 [Note] InnoDB: Database physically writes the file full: wait...
2015-12-13 15:21:53 17362 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-12-13 15:21:53 17362 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-12-13 15:21:53 17362 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-12-13 15:21:53 17362 [Warning] InnoDB: New log files created, LSN=45781
2015-12-13 15:21:53 17362 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-12-13 15:21:53 17362 [Note] InnoDB: Doublewrite buffer created
2015-12-13 15:21:53 17362 [Note] InnoDB: 128 rollback segment(s) are active.
2015-12-13 15:21:53 17362 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-12-13 15:21:53 17362 [Note] InnoDB: Foreign key constraint system tables created
2015-12-13 15:21:53 17362 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-12-13 15:21:53 17362 [Note] InnoDB: Tablespace and datafile system tables created.
2015-12-13 15:21:53 17362 [Note] InnoDB: Waiting for purge to start
2015-12-13 15:21:53 17362 [Note] InnoDB: 5.6.26 started; log sequence number 0
2015-12-13 15:21:53 17362 [Note] Binlog end
2015-12-13 15:21:53 17362 [Note] InnoDB: FTS optimize thread exiting.
2015-12-13 15:21:53 17362 [Note] InnoDB: Starting shutdown...
2015-12-13 15:21:54 17362 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2015-12-13 15:21:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-13 15:21:54 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.26) starting as process 17384 ...
2015-12-13 15:21:54 17384 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-12-13 15:21:54 17384 [Note] InnoDB: The InnoDB memory heap is disabled
2015-12-13 15:21:54 17384 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-12-13 15:21:54 17384 [Note] InnoDB: Memory barrier is not used
2015-12-13 15:21:54 17384 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-12-13 15:21:54 17384 [Note] InnoDB: Using CPU crc32 instructions
2015-12-13 15:21:54 17384 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-12-13 15:21:54 17384 [Note] InnoDB: Completed initialization of buffer pool
2015-12-13 15:21:54 17384 [Note] InnoDB: Highest supported file format is Barracuda.
2015-12-13 15:21:54 17384 [Note] InnoDB: 128 rollback segment(s) are active.
2015-12-13 15:21:54 17384 [Note] InnoDB: Waiting for purge to start
2015-12-13 15:21:54 17384 [Note] InnoDB: 5.6.26 started; log sequence number 1625977
2015-12-13 15:21:55 17384 [Note] Binlog end
2015-12-13 15:21:55 17384 [Note] InnoDB: FTS optimize thread exiting.
2015-12-13 15:21:55 17384 [Note] InnoDB: Starting shutdown...
2015-12-13 15:21:56 17384 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h edu-mysql-02 password 'new-password'
Alternatively you can run:
/usr/local/mysql/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/mysql/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 /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
1七、初始化腳本在/usr/local/mysql/下生成了配置文件my.cnf,須要更改該配置文件的全部者:
# ls -lah
[root@edu-mysql-01 mysql] # chown -Rf mysql:mysql /usr/local/mysql/my.cnf
18、注意:
(1)Tips:在啓動MySQL服務時,會按照必定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索mysql程序目錄下是否有my.cnf
(2)須要注意CentOS 6版操做系統的最小安裝完成後,即便沒有安裝mysql,在/etc目錄下也會存在一個my.cnf文件,建議將此文件改名爲其餘的名字,不然該文件會干擾源碼安裝的MySQL的正確配置,形成沒法啓動。修改/etc/my.cnf操做以下:
能夠:
mv /etc/my.cnf /etc/my.cnf.bak
也能夠:
刪除掉/etc/my.cnf這個文件:rm /etc/my.cnf
若是你須要用於生產環境,不要急着作下面的mysql啓動操做。建議把上一步驟中mysql初始化生成的/usr/local/mysql/my.cnf刪除,而後把你優化好的mysql配置文件my.cnf放到/etc下。(這是作mysql主從複製和mysql優化的經驗!)
(咱們這裏使用/etc/my.cnf)
1九、編輯/etc/my.cnf:
# vi /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
skip-external-locking
skip-name-resolve
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /home/mysql/data
tmpdir = /home/mysql/temp
# server_id = .....
socket = /usr/local/mysql/mysql.sock
log-error = /home/mysql/logs/mysql_error.log
pid-file = /home/mysql/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections=500
max_connect_errors = 6000
wait_timeout=605800
#open_tables = 600
#table_cache = 650
#opened_tables = 630
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 300
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 16k
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
lower_case_table_names=1
default-storage-engine = INNODB
innodb_buffer_pool_size = 2G
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_flush_method = O_DIRECT
#####################
thread_concurrency = 32
long_query_time= 2
slow-query-log = on
slow-query-log-file = /home/mysql/logs/mysql-slow.log
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
20、複製服務啓動腳本:
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
2一、啓動MySQL服務:
# service mysql start
Starting MySQL.. SUCCESS!
(初次啓動會在/usr/local/mysql目錄下生成mysql.sock文件)
2二、設置MySQL開機自動啓動服務:
# chkconfig mysql on
設置MySQL數據庫root用戶的本地登陸密碼(初始用戶沒有密碼):
# mysqladmin -u root password 'roncoo'
2三、登陸並修改MySQL用戶root的密碼:
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, 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.
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
修改root用戶密碼:
mysql> update user set Password = password('roncoo.com') where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 5 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
容許root遠程登陸,設置遠程登陸密碼:www.roncoo.com
mysql> use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'www.roncoo.com' WITH GRANT OPTION;
mysql> flush privileges;
mysql> exit;
注意:真實生產環境,應用操做不要使用root用戶。
從新登陸
[root@edu-mysql-01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.26-log Source distribution
Copyright (c) 2000, 2015, 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.
mysql>
2四、運行安全設置腳本,強烈建議生產服務器使用(可選):
[root@edu-mysql-01 ~]# /usr/local/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): ----->此處輸入root密碼
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n -----> 上已爲root設置了密碼,此處可輸n
... skipping.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y ------> 刪除匿名用戶
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n -----> 通常不容許root遠程登陸,可添加普通用戶,而後設置容許遠程登陸
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y -----> 刪除test庫及相應權限
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y -----> 從新加載權限表使設置生效
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
2五、重啓服務器,檢測mysql是否能開機自動啓動:
[root@edu-mysql-01 ~] # reboot