真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝

本篇文章給大家主要講的是關(guān)于一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝的內(nèi)容,感興趣的話就一起來看看這篇文章吧,相信看完一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝對大家多少有點(diǎn)參考價(jià)值吧。

創(chuàng)新互聯(lián)公司是一家成都網(wǎng)站建設(shè)、做網(wǎng)站,提供網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),網(wǎng)站制作,建網(wǎng)站,按需網(wǎng)站策劃,網(wǎng)站開發(fā)公司,2013年開創(chuàng)至今是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價(jià)值為核心業(yè)務(wù),全程參與項(xiàng)目的網(wǎng)站策劃設(shè)計(jì)制作,前端開發(fā),后臺(tái)程序制作以及后期項(xiàng)目運(yùn)營并提出專業(yè)建議和思路。

一、系統(tǒng)環(huán)境

1.1操作系統(tǒng)

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@localhost ~]# uname -rm
10.0-693.el7.x86_64 x86_64
[root@localhost ~]# 

1.2 安裝前環(huán)境監(jiān)測

1.2.1.SELinux和系統(tǒng)防火墻關(guān)閉

檢查selinux

[root@localhost ~]# sestatus -v   
SELinux status:                 disabled
[root@localhost ~]# 

或者使用使用getenforce檢查

[root@localhost ~]# getenforce 
Disabled

臨時(shí)關(guān)閉selinux

[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# 

永久關(guān)閉,需要修改SELinux的配置文件/etc/selinux/config

[root@localhost ~]# vim /etc/selinux/config
This file controls the state of SELinux on the system.
SELINUX= can take one of these three values:
enforcing - SELinux security policy is enforced.
permissive - SELinux prints warnings instead of enforcing.
disabled - No SELinux policy is loaded.
SELINUX=disabled
SELINUXTYPE= can take one of three two values:
targeted - Targeted processes are protected,
minimum - Modification of targeted policy. Only selected processes are protected. 
mls - Multi Level Security protection.
SELINUXTYPE=targeted

防火墻設(shè)置
查看當(dāng)前防火墻狀態(tài),已經(jīng)關(guān)閉,而且開機(jī)不自啟動(dòng)

[root@localhost ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

臨時(shí)關(guān)閉
[root@localhost ~]# systemctl stop firewalld.service
永久關(guān)閉,開機(jī)不啟動(dòng)
[root@localhost ~]# systemctl disable firewalld.service

1.2.2.swap分區(qū) 建議不配置或者分配4GB足夠

[root@localhost soft]# free -m
total        used        free      shared  buff/cache   available
Mem:           1823         294        1163           9         366        1339
Swap:          2047           0        2047

1.2.3.文件系統(tǒng)的選擇,推薦xfs(方便管理,支持動(dòng)態(tài)擴(kuò)容)

[root@localhost ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        17G  5.0G   13G  29% /
devtmpfs                devtmpfs  897M     0  897M   0% /dev
tmpfs                   tmpfs     912M     0  912M   0% /dev/shm
tmpfs                   tmpfs     912M  9.1M  903M   1% /run
tmpfs                   tmpfs     912M     0  912M   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  179M  836M  18% /boot
tmpfs                   tmpfs     183M   12K  183M   1% /run/user/42
tmpfs                   tmpfs     183M     0  183M   0% /run/user/0

1.2.4.操作系統(tǒng)限制(ulimit -a查看 主要參數(shù)open files  max user processes )

[root@localhost ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7168
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 7168
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

二、開始安裝MySQL5.6版本

2.1安裝準(zhǔn)備

(1)軟件版本:5.6.16
(2)安裝方式:二進(jìn)制方式 方便、靈活、管理數(shù)據(jù)和配置文件便捷
其他安裝方式:rpm安裝、yum安裝
(3)硬件需求:虛擬機(jī)內(nèi)存大?。鹤钌?G
磁盤最少:40G
(4)系統(tǒng)環(huán)境:Centos6/7 Redhat 64位
安裝包管理在/opt/目錄下創(chuàng)建/opt/soft,在官網(wǎng)下載mysql安裝包,通過secureCRT或者xshell并上傳安裝包到此目錄。

[root@localhost ~]# ll /opt/soft/
total 297656
rw-r--r-- 1 root root      3222 Mar 22 16:59 my.cnf
rw-r--r-- 1 root root 304788904 Mar 13 20:30 mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
rw-r--r-- 1 root root      2032 May 11 23:35 mysql_install_binary5.6.16.sh

MySQL下載地址這里給出5.6.40,跟本次的5.6.16的大版本一致。
https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
如下是MySQL下載頁面,可以選擇需要的版本
https://dev.mysql.com/downloads/mysql/

2.2手動(dòng)安裝步驟如下

2.2.1三部曲

=>創(chuàng)建家目錄:(basedir),并授權(quán)
/usr/local
解壓mysql安裝包到家目錄    改名稱(隱藏版本號)

[root@localhost soft]# tar -zxvf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@localhost soft]# ll -d /usr/local/mysql*
lrwxrwxrwx  1 root root  46 May 15 09:09 /usr/local/mysql -> /usr/local/mysql-5.6.16-linux-glibc2.5-x86_64/
drwxr-xr-x 13 root root 213 May 15 09:06 /usr/local/mysql-5.6.16-linux-glibc2.5-x86_64
[root@localhost soft]# 

授權(quán)mysql家目錄給mysql用戶

[root@localhost soft]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)

如果沒有MySQL用戶,可以創(chuàng)建mysql用戶授權(quán)并查看

[root@localhost soft]# chown -R mysql:mysql /usr/local/mysql
[root@localhost soft]# ll -d /usr/local/mysql
lrwxrwxrwx 1 mysql mysql 46 May 15 09:09 /usr/local/mysql -> /usr/local/mysql-5.6.16-linux-glibc2.5-x86_64/

2曲=>創(chuàng)建數(shù)據(jù)目錄(datadir),并授權(quán)
/data/mysql/
授權(quán)數(shù)據(jù)目錄給mysql用戶

[root@localhost soft]# mkdir -p /data/mysql
[root@localhost soft]# ll -ld /data/mysql/
drwxr-xr-x 2 root root 6 May 15 09:13 /data/mysql/
[root@localhost soft]# chown -R mysql:mysql /data/mysql/
[root@localhost soft]# ll -ld /data/mysql/
drwxr-xr-x 2 mysql mysql 6 May 15 09:13 /data/mysql/

3曲=>配置文件 /etc/my.cnf(安裝階段暫時(shí)不需要細(xì)看配置文件)
使用已經(jīng)配置好的
問題:如果修改了/etc/my.cnf文件,只需要重啟MySQL服務(wù),然后會(huì)加載修改后的my.cnf配置文件。
my.cnf如下

[root@localhost soft]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/
socket = /tmp/mysql.sock
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit    = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
"/etc/my.cnf" [dos] 115L, 3222C                                                                                                    1,1           Top
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/
socket = /tmp/mysql.sock
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit    = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /data/mysql/slow.log
log-error = /data/mysql/error.log
long_query_time = 0.5
server-id = 3306100
log-bin = /data/mysql/mysql-binlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 128M
max_binlog_size = 128M
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
innodb_status_file = 1
innodb_status_output = 0
innodb_status_output_locks = 0
performance_schema
performance_schema = 1
performance_schema_instrument = '%=on'
innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"
[mysqldump]
quick
max_allowed_packet = 32M

2.2.2 一步走

(1)初始化MySQL(切換到mysql家目錄scripts目錄)
./mysql_install_db   --basedir=/usr/local/mysql --datadir=/mysql/data --defaults-/etc/my.cnf --user=mysql
-user=mysql 這樣初始化完成后,初始化生成的文件的權(quán)限都是mysql用戶,所以一定加--user=mysql參數(shù)。否則初始化完成后還需要單獨(dú)授權(quán)生成的文件。
初始化完成后,會(huì)有兩個(gè)OK提示,就成功完成mysql的初始化。此時(shí)查看/data/mysql下的文件,同時(shí)查看所有文件的權(quán)限是mysql

[root@localhost mysql]# cd /usr/local/mysql/scripts/
[root@localhost scripts]# ./mysql_install_db   --basedir=/usr/local/mysql --datadir=/data/mysql --defaults-/etc/my.cnf --user=mysql
Installing MySQL system tables...

一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝

查看日志

[root@localhost ~]# less /data/mysql/error.log |grep ERROR
05-15 09:18:07 4131 [ERROR] /usr/local/mysql/bin/mysqld: unknown option '--defaults-/etc/my.cnf'
05-15 09:18:07 4131 [ERROR] Aborting

一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝
粗心大意,把配置文件那邊寫錯(cuò)了。修改后繼續(xù)

[root@localhost scripts]# ./mysql_install_db   --basedir=/usr/local/mysql --datadir=/data/mysql --defaults-file=/etc/my.cnf --user=mysql
**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/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain 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

WARNING: Found existing config file /usr/local/mysql/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/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

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

2.2.3MySQL安裝成功。

一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝

2.2.4啟動(dòng)MySQL

[root@localhost ~]#   /usr/local/mysql/bin/mysqld_safe  &
[1] 5771
[root@localhost ~]# 180515 09:28:48 mysqld_safe Logging to '/data/mysql/error.log'.
09:28:48 mysqld_safe Starting mysqld daemon with databases from /data/mysql/
09:28:50 mysqld_safe mysqld from pid file /data/mysql//localhost.localdomain.pid ended

[1]+  Done                    /usr/local/mysql/bin/mysqld_safe
[root@localhost ~]# ps -ef|grep 3306
root       7094   3559  0 09:29 pts/2    00:00:00 grep --color=auto 3306

啟動(dòng)出錯(cuò),查看日志
一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝
日志顯示,3306端口正在使用,查看端口情況

[root@localhost ~]# netstat -nltp|grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1373/mysqld    
[root@localhost ~]# kill -9  1373
[root@localhost ~]# 

此時(shí)查看mysql以及端口3306

[root@localhost ~]# netstat -nltp|grep mysql
[root@localhost ~]# netstat -nltp|grep 3306

再次啟動(dòng)MySQL云服務(wù)器

[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe &
[1] 10033
[root@localhost ~]# 
[root@localhost ~]# 180515 09:38:52 mysqld_safe Logging to '/data/mysql/error.log'.
180515 09:38:52 mysqld_safe Starting mysqld daemon with databases from /data/mysql/

啟動(dòng)成功如下

[root@localhost ~]# ps -ef|grep mysql
root      10033   3559  0 09:38 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
mysql     11320  10033  3 09:38 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/ --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/error.log --open-files-limit=65535 --pid-file=/data/mysql//localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root      11355   3559  0 09:39 pts/2    00:00:00 grep --color=auto mysql
[root@localhost ~]# ps -ef|grep 3306
mysql     11320  10033  3 09:38 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/ --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/error.log --open-files-limit=65535 --pid-file=/data/mysql//localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root      11357   3559  0 09:39 pts/2    00:00:00 grep --color=auto 3306
[root@localhost ~]# 

2.2.5 MySQL密碼設(shè)置

登錄MySQL云服務(wù)器,默認(rèn)沒有密碼

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.16-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@db 09:39:  [(none)]> 

2.2.6安裝完成后的優(yōu)化

(1)密碼設(shè)置:目前root用戶沒有密碼,那么設(shè)置root用戶密碼

 root@db 09:42:  [(none)]> use mysql;
Database changed
root@db 09:42:  [mysql]> update user set password=password('123456') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
root@db 09:42:  [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

測試修改后密碼
//使用原來空密碼登錄,提示密碼錯(cuò)誤

[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

//使用新密碼登錄,成功。

[root@localhost ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.16-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@db 09:47:  [(none)]> 

(2)mysql遠(yuǎn)程登錄用戶設(shè)置,安裝完數(shù)據(jù)庫后mysql數(shù)據(jù)庫用戶的管理。 只保留一個(gè) localhost root

root@db 09:42:  [mysql]> use mysql
Database changed
root@db 09:43:  [mysql]> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1                   | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
null
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)

root@db 09:43:  [mysql]>  delete from user where host!='localhost' or user!='root';
Query OK, 5 rows affected (0.01 sec)

root@db 09:44:  [mysql]> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)

root@db 09:44:  [mysql]> 

【補(bǔ)充】

(1)我這里提前配置好了MySQL的環(huán)境變量
環(huán)境變量如下,環(huán)境變量修改

echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

(2)可以通過msyql自帶的腳本,啟動(dòng)mysql

[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
[root@localhost ~]# ll -ld /etc/init.d/mysqld 
-rwxr-xr-x 1 root root 10880 May 15 09:34 /etc/init.d/mysqld
[root@localhost ~]# /etc/init.d/mysqld status
 SUCCESS! MySQL running (11320)

我們剛剛啟動(dòng)了MySQL 因此現(xiàn)在看到的狀態(tài)是正在運(yùn)行。
(3)加入開機(jī)自啟動(dòng)

[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
null
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

如上使用了centos6的命令添加開機(jī)自動(dòng)開啟服務(wù)的命令,可以使用7版本新的命令。
查看系統(tǒng)當(dāng)前默認(rèn)啟動(dòng)項(xiàng)目的方法
[root@localhost ~]# systemctl list-unit-files
以上步驟,通過shell腳本實(shí)現(xiàn),這里,把MySQL二進(jìn)制包,MySQL安裝shell,配置文件都放在/opt/soft目錄下

[root@localhost ~]# ll /opt/soft/
total 297656
rw-r--r-- 1 root root      3222 Mar 22 16:59 my.cnf
rw-r--r-- 1 root root 304788904 Mar 13 20:30 mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
rw-r--r-- 1 root root      2032 May 11 23:35 mysql_install_binary5.6.16.sh

腳本如下

#!/bin/sh
#測試系統(tǒng):Centos6.5 Centos7.4
#腳本使用前,提前準(zhǔn)備好二進(jìn)制安裝包,創(chuàng)建/opt/soft放在/opt/soft下 配置文件放在/etc/my.cnf
#腳本不足:沒有對預(yù)定好的mysql家目錄 /usr/local/mysql和mysql數(shù)據(jù)目錄/data/mysql以及/etc/my.cnf做判斷,默認(rèn)是這兩個(gè)目錄不存在或者目錄是沒有內(nèi)容的,如果有內(nèi)容可能會(huì)有警告
#對對應(yīng)變量進(jìn)行賦值
group=mysql
user=mysql
basedir=/usr/local/mysql/
datadir=/data/mysql/
mysql_package="mysql-5.6.16-linux-glibc2.5-x86_64"

#準(zhǔn)備開始
echo "Installing :" $mysql_package

#--用戶創(chuàng)建--
#匹配該文件中以$group變量值開頭的內(nèi)容
#創(chuàng)建組,如果組存在就直接執(zhí)行如下命令
#--egrep在文件中查找指定模式 
#--^表示匹配的字符必須在最前邊 字符$與^類似,匹配最末的字符.

egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd $group
fi

#創(chuàng)建用戶,如果用戶存在就直接執(zhí)行如下命令
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd $user -g $group -p 123456 -s /sbin/nologin -M
fi
#第一曲:解壓二進(jìn)制安裝包
tar -zxvf /opt/soft/$mysql_package.tar.gz -C /usr/local

#重命名 隱藏版本號
cd /usr/local/
mv $mysql_package mysql

#第二曲:創(chuàng)建數(shù)據(jù)目錄
mkdir -p $datadir

#授權(quán)--授權(quán)mysql家目錄basedir和mysql數(shù)據(jù)目錄datadir
cd /usr/local/mysql
chown -R $group:$user $basedir
mkdir -p $datadir
chown -R $group:$user $datadir
#第三曲:配置文件(提前準(zhǔn)備好)
cp /opt/soft/my.cnf /etc/
#一步走:mysql初始化
cd $basedir/scripts/
./mysql_install_db --user=$user --basedir=$basedir --datadir=$datadir --defaults-file=/etc/my.cnf
#加入開機(jī)自啟動(dòng)
cp $basedir/support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
#環(huán)境變量修改
echo "export PATH=$PATH:$basedir/bin" >> /etc/profile
source /etc/profile

#啟動(dòng)mysql服務(wù)
/etc/init.d/mysqld start
#啟動(dòng)結(jié)果
echo $mysql_package "install success."
#登陸mysql
mysql```

腳本根據(jù)如上的安裝步驟寫的,這里,在另外一臺(tái)云服務(wù)器上通過該腳本一鍵部署安裝MySQL
如下

[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# ll
total 297660

-rw-r--r--. 1 root root      3222 Apr 12 10:16 my.cnf
-rw-r--r--. 1 root root 304788904 Mar 13 20:30 mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 root root      1908 Apr 12 11:55 mysql_install_binary5.6.16.sh
-rw-r--r--. 1 root root      1904 Apr 12 11:57 mysql_install_binary5.6.33.sh
[root@localhost soft]#

[root@localhost soft]# sh mysql_install_binary5.6.16
Installing MySQL system tables...OK

Filling help tables...OK

安裝成功,啟動(dòng)失敗。

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

Starting MySQL.................. ERROR! The server quit without updating PID file (/data/mysql//localhost.localdomain.pid).
mysql-5.6.16-linux-glibc2.5-x86_64 install success.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

查看日志

[root@localhost soft]# cat /data/mysql/error.log |grep ERROR
2018-05-15 11:28:23 8163 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use
2018-05-15 11:28:23 8163 [ERROR] Do you already have another mysqld server running on port: 3306 ?
2018-05-15 11:28:23 8163 [ERROR] Aborting

`和上面手動(dòng)安裝錯(cuò)誤一樣,kill掉占用3306的線程`

[root@localhost soft]# netstat -nltp|grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      3066/mysqld        
[root@localhost soft]# kill -9 3066
[root@localhost soft]# netstat -nltp|grep 3306

再次啟動(dòng)MySQL

[root@localhost soft]# /etc/init.d/mysqld start
Starting MySQL.................. SUCCESS!
[root@localhost soft]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.16-log MySQL Community Server (GPL)
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.
null
root@db 11:37:  [(none)]>

啟動(dòng)成功,到此,MySQL二進(jìn)制安裝部署,一鍵安裝完成。

由于時(shí)間有限,難免有錯(cuò)誤,請大家給與指正。希望對各位學(xué)習(xí)有幫助。

以上關(guān)于一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝詳細(xì)內(nèi)容,對大家有幫助嗎?如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。


分享名稱:一鍵實(shí)現(xiàn)MySQL5.6.16二進(jìn)制源碼安裝
分享地址:http://weahome.cn/article/ijegdj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部