yum install epel-release –y
yum install cmake –y
yum install autoconf automake libtool
yum install -y krb5 krb5-devel libidn libidn-devel openssl openssl-devel -y
yum install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devdel -y
yum install zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel -y
yum install ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel -y
yum install perl-Data_dumper python-devel -y
tar zxvf /root/mysql-boost-5.7.18.tar.gz
cd /root/mysql-5.7.18
cmake \
-DWITH_BOOST=boost \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18 \
-DMYSQL_DATADIR=/usr/local/mysql-5.7.18/data \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-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_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DMYSQL_USER=mysql \
-DWITH_ZLIB=bundled \
-DWITH_READLINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
然后编译和安装:
make && make install
mkdir –p /usr/local/mysql-5.7.18/data/3306/data
mkdir –p /usr/local/mysql-5.7.18/data/3307/data
useradd mysql -s /sbin/nologin –M
[client]
port = 3306
socket = /usr/local/mysql-5.7.18/data/3306/mysql.sock
[mysqld_safe]
log-error = /usr/local/mysql-5.7.18/data/3306/mysql.err
pid-file = /usr/local/mysql-5.7.18/data/3306/mysql.pid
[mysqld]
#
# * Basic Settings
#
server-id = 1
log-bin= /usr/local/mysql-5.7.18/data/3306/mysql-bin
user = mysql
pid-file = /usr/local/mysql-5.7.18/data/3306/mysql.pid
socket = /usr/local/mysql-5.7.18/data/3306/mysql.sock
port = 3306
basedir = /usr/local/mysql-5.7.18
datadir = /usr/local/mysql-5.7.18/data/3306/data
tmpdir = /tmp
open_files_limit=1024
external-locking = false
character-set-server=utf8
default-storage-engine=MyISAM
bind-address = 0.0.0.0
max_allowed_packet = 8M
thread_stack = 192K
thread_cache_size = 8
max_connections = 800
max_connect_errors = 300
#table_cache = 64
#thread_concurrency = 10
query_cache_limit = 1M
query_cache_size = 2M
join_buffer_size=1M
sort_buffer_size=1M
long_query_time = 1
relay-log = /usr/local/mysql-5.7.18/data/3306/relay-bin
relay-log-info-file =/usr/local/mysql-5.7.18/data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
key_buffer_size=16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors =1032,1062
replicate-ignore-db = mysql
#innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:12M:autoextend
#innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
#innodb_log_files_in_groups = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[client]
port = 3307
socket = /usr/local/mysql-5.7.18/data/3307/mysql.sock
[mysqld_safe]
log-error = /usr/local/mysql-5.7.18/data/3307/mysql.err
pid-file = /usr/local/mysql-5.7.18/data/3307/mysql.pid
[mysqld]
#
# * Basic Settings
#
server-id = 2
user = mysql
pid-file = /usr/local/mysql-5.7.18/data/3307/mysql.pid
socket = /usr/local/mysql-5.7.18/data/3307/mysql.sock
port = 3307
basedir = /usr/local/mysql-5.7.18
datadir = /usr/local/mysql-5.7.18/data/3307/data
tmpdir = /tmp
open_files_limit=1024
external-locking = false
character-set-server=utf8
default-storage-engine=MyISAM
bind-address = 0.0.0.0
max_allowed_packet = 8M
thread_stack = 192K
thread_cache_size = 8
max_connections = 800
max_connect_errors = 300
#table_cache = 64
#thread_concurrency = 10
query_cache_limit = 1M
query_cache_size = 2M
join_buffer_size=1M
sort_buffer_size=1M
long_query_time = 1
relay-log = /usr/local/mysql-5.7.18/data/3307/relay-bin
relay-log-info-file =/usr/local/mysql-5.7.18/data/3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
key_buffer_size=16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors =1032,1062
replicate-ignore-db = mysql
#innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:12M:autoextend
#innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
#innodb_log_files_in_groups = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
touch /usr/local/mysql-5.7.18/data/3306/mysql.err
touch /usr/local/mysql-5.7.18/data/3307/mysql.err
chmod 766 /usr/local/mysql-5.7.18/data/3306/mysql.err
chmod 766 /usr/local/mysql-5.7.18/data/3307/mysql.err
#!/bin/sh
port=3306
mysql_user="root"
mysql_pwd="mypassword"
cmd_path="/usr/local/mysql-5.7.18/bin"
mysql_sock="/usr/local/mysql-5.7.18/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
/bin/sh ${cmd_path}/mysqld_safe --defaults-file=/usr/local/mysql-5.7.18/data/${port}/my.cnf 2>&1 > /dev/null &
else
printf "MySQL is running...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /usr/local/mysql-5.7.18/data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /usr/local/mysql-5.7.18/data/${port}/mysql {start|stop|restart}\n"
esac
#!/bin/sh
port=3307
mysql_user="root"
mysql_pwd="mypassword"
cmd_path="/usr/local/mysql-5.7.18/bin"
mysql_sock="/usr/local/mysql-5.7.18/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
/bin/sh ${cmd_path}/mysqld_safe --defaults-file=/usr/local/mysql-5.7.18/data/${port}/my.cnf 2>&1 > /dev/null &
else
printf "MySQL is running...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /usr/local/mysql-5.7.18/data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /usr/local/mysql-5.7.18/data/${port}/mysql {start|stop|restart}\n"
esac
chmod 755 /usr/local/mysql-5.7.18/data/3306/mysql
chmod 755 /usr/local/mysql-5.7.18/data/3307/mysql
chown –R mysql:mysql /usr/local/mysql-5.7.18
/usr/local/mysql-5.7.18/bin/mysql_install_db \
--basedir=/usr/local/mysql-5.7.18 \
--datadir=/usr/local/mysql-5.7.18/data/3306/data \
--user=mysql
/usr/local/mysql-5.7.18/bin/mysql_install_db \
--basedir=/usr/local/mysql-5.7.18 \
--datadir=/usr/local/mysql-5.7.18/data/3307/data \
--user=mysql
/usr/local/mysql-5.7.18/bin/mysqld --initialize \
--basedir=/usr/local/mysql-5.7.18 \
--datadir=/usr/local/mysql-5.7.18/data/3306/data \
--user=mysql
/usr/local/mysql-5.7.18/bin/mysqld --initialize \
--basedir=/usr/local/mysql-5.7.18 \
--datadir=/usr/local/mysql-5.7.18/data/3307/data \
--user=mysql
2017-06-09T13:45:09.590690Z 1 [Note] A temporary password is generated for root@localhost: GdlR7&+w
2017-06-09T13:46:48.721250Z 1 [Note] A temporary password is generated for root@localhost: Z>B#5IfIFAfj
/usr/local/mysql-5.7.18/data/3306/mysql start
/usr/local/mysql-5.7.18/data/3307/mysql start
[root@localhost ~]# /usr/local/mysql-5.7.18/data/3306/mysql start
Starting MySQL...
[root@localhost ~]# /usr/local/mysql-5.7.18/data/3307/mysql start
Starting MySQL...
[root@localhost ~]# netstat -lntp | grep 330
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 4480/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3817/mysqld
[root@localhost ~]# tail /usr/local/mysql-5.7.18/data/3306/mysql.err
2017-06-10T14:41:51.366238Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2017-06-10T14:41:51.366625Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2017-06-10T14:41:51.371787Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2017-06-10T14:41:51.416687Z 0 [Note] Event Scheduler: Loaded 0 events
2017-06-10T14:41:51.416855Z 0 [Note] /usr/local/mysql-5.7.18/bin/mysqld: ready for connections.
Version: '5.7.18-log' socket: '/usr/local/mysql-5.7.18/data/3306/mysql.sock' port: 3306 Source distribution
2017-06-10T14:41:51.416862Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
2017-06-10T14:41:51.416864Z 0 [Note] Beginning of list of non-natively partitioned tables
2017-06-10T14:41:51.473660Z 0 [Note] End of list of non-natively partitioned tables
2017-06-10T14:42:07.539386Z 3 [Note] Start binlog_dump to master_thread_id(3) slave_server(2), pos(mysql-bin.000001, 2654)
cd /usr/local/mysql-5.7.18
./bin/mysql -u root -p -S ./data/3306/mysql.sock
cd /usr/local/mysql-5.7.18
./bin/mysql -u root -p -S ./data/3307/mysql.sock
[root@localhost ~]# cd /usr/local/mysql-5.7.18
[root@localhost mysql-5.7.18]# ./bin/mysql -u root -p -S ./data/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18
2017-06-09T13:45:09.590690Z 1 [Note] A temporary password is generated for root@localhost: GdlR7&+w
2017-06-09T13:46:48.721250Z 1 [Note] A temporary password is generated for root@localhost: Z>B#5IfIFAfj
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('your_password');
Query OK, 0 rows affected (0.03 sec)
[mysqld]
#
# * Basic Settings
#
server-id = 1
log-bin= /usr/local/mysql-5.7.18/data/3306/mysql-bin
replicate-ignore-db = mysql
[root@localhost ~]# egrep "server-id|log-bin" /usr/local/mysql-5.7.18/data/3306/my.cnf
server-id = 1
log-bin = /usr/local/mysql-5.7.18/data/3306/mysql-bin
mysql> show variables like "server_id";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show variables like "log_bin";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show grants for "replication"@"%";
+-----------------------------------------------------+
| Grants for replication@% |
+-----------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%' |
+-----------------------------------------------------+
1 row in set (0.00 sec)
[mysqld]
#
# * Basic Settings
#
server-id = 2
[root@localhost ~]# egrep "server-id|log-bin" /usr/local/mysql-5.7.18/data/3307/my.cnf
server-id = 1
cd /usr/local/mysql-5.7.18
./bin/mysql -u root –p -S ./data/3307/mysql.sock
CHANGE MASTER TO \
MASTER_HOST='127.0.0.1', \
MASTER_PORT=3306, \
MASTER_USER='replication', \
MASTER_PASSWORD='your_password', \
MASTER_LOG_FILE='mysql-bin.000003', \
MASTER_LOG_POS=154;
mysql> create database zhoufoxcn;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zhoufoxcn |
+--------------------+
5 rows in set (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zhoufoxcn |
+--------------------+
5 rows in set (0.00 sec)
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 488
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 488
Relay_Log_File: relay-bin.000008
Relay_Log_Pos: 701
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 488
Relay_Log_Space: 1115
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: da584607-4d19-11e7-8903-080027f376f5
Master_Info_File: /usr/local/mysql-5.7.18/data/3307/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified