mysql源码安装
检查是否安装了MySQL
root@bd-qa-mongodb-85:~#rpm -qa | grep -i mysql
mysql-libs-5.1.73-5.el6_6.x86_64
使用yum来删除MySQL
root@bd-qa-mongodb-85:~#yum -y remove mysql-libs
安装依赖包
root@bd-qa-mongodb-85:~#yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
下载相应源码包
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost\_1\_59\_0.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.9.tar.gz
添加mysql用户
useradd -M -s /sbin/nologin mysql
解压
tar xzf boost_1_59_0.tar.gz
tar xzf mysql-5.7.9.tar.gz
创建文件夹
mkdir -p /data/mysql
cd mysql-5.7.9
预编译
首先cmake参数的一些解释
-DCMAKE_INSTALL_PREFIX= 安装根目录
-DSYSCONFDIR=配置文件(my.cnf)目录
-DCMAKE_INSTALL_PREFIX= unix套接字目录
-DDEFAULT_CHARSET= 默认字符集
-DDEFAULT_COLLATION=默认编码
-DWITH_EXTRA_CHARSETS= 额外的编码,请使用ALL来编译。
-DWITH_MYISAM_STORAGE_ENGINE=1 编译myisam存储引擎,默认的存储引擎,不加也可以
-DWITH_INNOBASE_STORAGE_ENGINE=1 支持InnoDB存储引擎,这个也是默认安装的
-DWITH_READLINE=1 使用readline功能
-DENABLED_LOCAL_INFILE=1 可以使用load data infile命令从本地导入文件
-DMYSQL_DATADIR=数据库 数据目录
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1
注意:#从MySQL 5.7.5开始Boost库是必需的
编译安装
root@bd-qa-mongodb-85:/opt/app/mysql/mysql-5.7.9# make -j `grep processor /proc/cpuinfo | wc -l` #编译很消耗系统资源,小内存可能编译通不过
root@bd-qa-mongodb-85:/opt/app/mysql/mysql-5.7.9# make install
三个节点均执行上述操作
启动脚本,设置开机自启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig —add mysqld
chkconfig mysqld on
root@bd-qa-mongodb-85:/opt/app/mysql/config#cat my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = ‘SET NAMES utf8mb4’
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
初始化数据库
/usr/local/mysql/bin/mysqld —initialize-insecure —user=mysql —basedir=/usr/local/mysql —datadir=/data/mysql
注:
之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
“–initialize”会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure”不会生成密码
–datadir目标目录下不能有数据文件
启动数据库
root@bd-qa-mongodb-85:~#service mysqld start
Starting MySQL. SUCCESS!
//添加path路径: vim /etc/profile 添加下面2行 在文件的结尾
[root@oracle mysql-5.7.9]# export MYSQL_HOME=/usr/local/mysql
[root@oracle mysql-5.7.9]# export PATH=$PATH:$MYSQL_HOME/bin
//修改root密码,和授权新用户:
mysql> set password=password(‘fafa123’);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all on *.* to dba_user@’%’ identified by ‘fafa123’;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
检查用户权限
mysql> select user,host,authentication_string from mysql.user;
+—————-+—————-+—————————————————————-+
| user | host | authentication_string |
+—————-+—————-+—————————————————————-+
| root | localhost | *8C53D2FE0782BF01ACB952CF9C84B79701B310E5 |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| dba_user | % | *8C53D2FE0782BF01ACB952CF9C84B79701B310E5 |
+—————-+—————-+—————————————————————-+
3 rows in set (0.03 sec)
测试登录
[ root@oracle mysql-5.7.9]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9-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>
成功
卸载数据库,注意删除的时候,直接删除目录就行
还没有评论,来说两句吧...