编译安装mysql-5.6.40

环境说明

系统版本     CentOS 7.2 x86_64

软件版本     mysql-5.6.40

[[email protected] ~]# mkdir -p /service/tools

[[email protected] ~]# mkdir /application

[[email protected] ~]# yum install ncurses-devel libaio-devel cmake gcc gcc-c++ glibc openssl-devel bison-devel -y

[[email protected] ~]# useradd -s /sbin/nologin -M mysql

[[email protected] ~]# cd /service/tools/

[[email protected] tools]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.6/mysql-5.6.40.tar.gz

[[email protected] tools]# tar xf mysql-5.6.40.tar.gz

[[email protected] tools]# cd mysql-5.6.40/

[[email protected] tools]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 \

-DMYSQL_DATADIR=/application/mysql-5.6.40/data \

-DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_ZLIB=bundled \

-DWITH_SSL=bundled \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLE_DOWNLOADS=1 \

-DWITH_DEBUG=0

参数说明:

cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 \    #指定安装目录

-DMYSQL_DATADIR=/application/mysql-5.6.40/data \        #指定数据data目录

-DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/mysql.sock \ #指定sock路径

-DDEFAULT_CHARSET=utf8 \                                    #指定默认字符集

-DDEFAULT_COLLATION=utf8_general_ci \                    #指定默认校验规则

-DWITH_EXTRA_CHARSETS=all \                                #指定扩展支持的字符集

-DWITH_INNOBASE_STORAGE_ENGINE=1 \                        #启用innodb存储引擎

-DWITH_FEDERATED_STORAGE_ENGINE=1 \                        #启用Federated存储引擎

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \                        #启用BLACKHOLE引擎

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \                        #禁用EXAMPLE_STORAGE_ENGINE

-DWITH_ZLIB=bundled \                                        #启用zlib支持

-DWITH_SSL=bundled \                                        #启用ssl库支持

-DENABLED_LOCAL_INFILE=1 \                                #启用加载本地数据

-DWITH_EMBEDDED_SERVER=1 \                                #嵌入式服务器

-DENABLE_DOWNLOADS=1 \                                    #编译时允许自主下载相关文件

-DWITH_DEBUG=0                                                #禁用调试模式

[[email protected] tools]# make && make install

[[email protected] mysql-5.6.40]# ln -s /application/mysql-5.6.40/ /application/mysql    #创建软链接

[[email protected] mysql-5.6.40]# \cp support-files/my*.cnf /etc/my.cnf    #拷贝配置文件

[[email protected] mysql-5.6.40]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql                                    #初始化

[[email protected] mysql-5.6.40]# chown -R mysql:mysql  /application/mysql/    #修改目录所属

[[email protected] mysql-5.6.40]# \cp support-files/mysql.server /etc/init.d/mysqld    #拷贝启动脚本

[[email protected] mysql-5.6.40]# chmod +x /etc/init.d/mysqld                #添加执行权限

[[email protected] mysql-5.6.40]# ll /etc/init.d/mysqld                        #检查

-rwxr-xr-x 1 root root 10619 7月   1 16:06 /etc/init.d/mysqld

[[email protected] mysql-5.6.40]# /etc/init.d/mysqld start                    #启动mysql

Starting MySQL.Logging to '/application/mysql-5.6.40/data/db01.err'.

SUCCESS!

[[email protected] mysql-5.6.40]# ln -s /application/mysql/bin/* /usr/bin/ #创建命令快捷方式

或者

[[email protected] ~]# echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile

[[email protected] ~]# tail -1 /etc/profile

[[email protected] ~]# source /etc/profile

 

基本优化(清理用户及无用数据库)

mysql> select user,host from mysql.user;

mysql> drop user ''@'db01';

mysql> drop user ''@'localhost';

mysql> drop user 'root'@'db01';

mysql> drop user 'root'@'::1';

mysql> select user,host from mysql.user;

mysql> drop database test;

mysql> show databases;

或者根据mysql_secure_installation命令进行向导优化