一、操作环境
华为云服务 Centos 6.5_64bit最小化安装内网IP:10.124.156.237
mysql-5.6.20.tar.gz
二、源码编译安装流程
1.基础环境搭建
由于操作系统是最小化安装,因此一些常用的编译环境是没有安装的;加上我们的操作环境是内网,所以不能使用yum源。解决这个问题,可以从华为云购买一个临时公网Ip与我们服务器的内网IP进行邦定,这样我们就可以使用yum源来安装必要的编译环境了。
yum -y install gccgcc-c++ vim tree make cmake autoconf openssl openssl-devel openssl-clients curlcurl-devel wget rsync expect readline readline-devel bison bison-devel pcre pcre-devel zlib-devel zlib freetype freetype-devel
- 上面这段代码可以满足基本的环境操作,不仅仅适用于在安装mysql的过程中。
2.mysql用户以及必需目录
在mysql运行中涉及到很多权限的问题,所以提前进行这方面的准备,避免在后期遇到一些不必要的权限问题。
groupadd mysql
useradd -g mysql mysql
mkdir -p/home/mysql/data/data_3306/binlog /home/mysql/data/data_3306/relay_log/home/mysql/data/data_3306/socket
mkdir -p/home/mysql/data/data_3307/binlog /home/mysql/data/data_3307/relay_log/home/mysql/data/data_3307/socket
chown –Rmysql.mysql /home/mysql/
3. 源码编译安装
cd /usr/local/src/
tar xf mysql-5.6.20.tar.gz
cd mysql-5.6.20
cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data-DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock-DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1-DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci
make && makeinstall
4. 初始化设置
1)单实例初始化
/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql
2)多实例初始化
首先修改配置文件
vim /etc/my.cnf
[mysqld_multi]
mysqld =/usr/local/mysql/bin/mysqld_safe
mysqladmin =/usr/local/mysql/bin/mysqladmin
#log = /home/mysql/data/log/mysqld_multi.log
#user = root
#password = password
[mysqld1]
socket =/home/mysql/data/data_3306/socket/mysql.sock
port = 3306
pid-file =/home/mysql/data/data_3306/3306.pid
datadir =/home/mysql/data/data_3306
user = mysql
skip-name-resolve
lower_case_table_names=1
innodb_file_per_table=1
back_log = 50
max_connections = 300
max_connect_errors =1000
table_open_cache =2048
max_allowed_packet =16M
binlog_cache_size = 2M
max_heap_table_size =64M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine= MYISAM
thread_stack = 192K
transaction_isolation= REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time = 1
server-id = 1
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size =2M
bulk_insert_buffer_size= 64M
myisam_sort_buffer_size= 128M
myisam_max_sort_file_size= 10G
myisam_repair_threads= 1
myisam_recover
innodb_additional_mem_pool_size= 16M
innodb_buffer_pool_size= 200M
innodb_data_file_path= ibdata1:10M:autoextend
innodb_file_io_threads= 8
innodb_thread_concurrency= 16
innodb_flush_log_at_trx_commit= 1
innodb_log_buffer_size= 16M
innodb_log_file_size =512M
innodb_log_files_in_group= 3
innodb_max_dirty_pages_pct= 60
innodb_lock_wait_timeout= 120
[mysqld2]
socket =/home/mysql/data/data_3307/socket/mysql.sock
port = 3307
pid-file =/home/mysql/data/data_3307/3307.pid
datadir = /home/mysql/data/data_3307
user = mysql
skip-name-resolve
lower_case_table_names=1
innodb_file_per_table=1
back_log = 50
max_connections = 300
max_connect_errors =1000
table_open_cache =2048
max_allowed_packet =16M
binlog_cache_size = 2M
max_heap_table_size =64M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine= MYISAM
thread_stack = 192K
transaction_isolation= REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time = 1
server-id = 1
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size =2M
bulk_insert_buffer_size= 64M
myisam_sort_buffer_size= 128M
myisam_max_sort_file_size= 10G
myisam_repair_threads= 1
myisam_recover
innodb_additional_mem_pool_size= 16M
innodb_buffer_pool_size= 200M
innodb_data_file_path= ibdata1:10M:autoextend
innodb_file_io_threads= 8
innodb_thread_concurrency= 16
innodb_flush_log_at_trx_commit= 1
innodb_log_buffer_size= 16M
innodb_log_file_size =512M
innodb_log_files_in_group= 3
innodb_max_dirty_pages_pct= 60
innodb_lock_wait_timeout= 120
[mysqldump]
quick
max_allowed_packet =256M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size =512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit =8192
其次进行初始化操作:
scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data/data_3306 --user=mysql
scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data/data_3307 --user=mysql
5. 修改环境变量
这一步至关重要,因为涉及到启动时会报找不到my_print_defaults命令的错误,同时也为了以后方便操作。
vim /etc/profile
在末行添加exportPATH=$PATH:/usr/sbin/:/usr/local/mysql/bin
保存退出执行:source /etc/profile
6. Mysql数据库的启动和关闭
/usr/local/mysql/bin/mysqld_multi start 1,2 –> mysqld_multi start 1,2
mysqld_multi stop 1
mysqld_multi stop 2
7. 数据库的连接
1)本地连接:
mysql -S/home/mysql/data/data_3306/socket/mysql.sock #第一个实例连接
mysql -S /home/mysql/data/data_3307/socket/mysql.sock #第二个实例连接
2)远程连接:
mysql –h 10.124.156.237 –P 3306 –u root –p123 #指定端口号连接
mysql –h 10.124.156.237 –P 3307 –u root –p123
三、单机多实例作为多机‘从’设置
四、报错总结
1.启动报错
WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.
ABORT: Can‘t find command ‘my_print_defaults‘.
This command is available from the latest MySQL
distribution. Please make sure you have the command
in your PATH.
问题解析:找不到my_print_defaults命令,没有设置环境变量的缘故
问题解决:cp /usr/local/mysql/bin/my_print_defaults/usr/bin/
cp/usr/local/mysql/bin/mysqld_multi /usr/bin/
2. 初始化报错
FATAL ERROR: The parentdirectory for the data directory ‘/home/data/data_3306‘ does not exis
If that path was really intended, please create that directory path andthen
restart this script.
If some other path was intended, please use the correct path whenrestarting this script.
问题解析:文件目录不存在。没有执行编译安装中的第2步,或者配置文件my.cnf中填写有误
问题解决:环境变量的配置
vim /etc/profile
在末行添加exportPATH=$PATH:/usr/sbin/:/usr/local/mysql/bin
保存退出执行:source /etc/profile
检查配置文件my.cnf