首页 > 代码库 > msyql 编译安装
msyql 编译安装
配置YUM (本地)
[root@mysqlserver yum.repos.d]# cat CentOS-Base.repo
[base]
baseurl=file:///mnt
enabled=1
gpgcheck=0
实验环境:
[root@mysqlserver yum.repos.d]# cat /etc/centos-release
CentOS release 6.6 (Final)
建mysql用户:
[root@mysqlserver mysql-5.6.36]# useradd -s /sbin/nologin -M mysql
[root@mysqlserver mysql-5.6.36]# mkdir -p /home/oldboy/tools
[root@mysqlserver mysql-5.6.36]# tar zxvf mysql-5.6.36.tar.gz
[root@mysqlserver mysql-5.6.36]# cd mysql-5.6.36
[root@mysqlserver mysql-5.6.36]# mkdir -p /application/mysql-5.6.36/data
[root@mysqlservermysql-5.6.36]#cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \
-DMYSQL_DATADIR=/application/mysql-5.6.36/data\
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.34/tmp/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
[root@mysqlserver mysql-5.6.36]# make && make install
为MySQL安装路径设置不带版本号的软链接/application/mysql,操作命令如下:
[root@mysqlserver ~]# ln -s /application/mysql-5.6.36/ /application/mysql
[root@mysqlserver ~]# mv /etc/my.cnf /etc/my.cnf.bak
#提示:在CentOS6.8版操作系统最小化安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
#在启动MySQL服务时,会按照一定的顺序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是/application/mysql-5.6.36/my.cnf,这是新版MySQL的配置文件的默认位置!
授权:
[root@mysqlserver application]# chown -R mysql.mysql /application/mysql/
[root@mysqlserver application]# chmod -R 1777 /tmp
配置环境变量:
[root@mysqlserver application]# echo ‘export PATH=/application/mysql/bin:$PATH‘>>/etc/profile
[root@mysqlserver application]# source /etc/profile
[root@mysqlserver application]# echo $PATH
[root@mysqlserver application]# cd /application/mysql/scripts/
[root@mysqlserverscripts]#./mysql_install_db --basedir=/application/mysql/--datadir=/application/mysql/data --user=mysql
报错:
[root@mysqlserver scripts]# ./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
Installing MySQL system tables...2017-05-30 12:13:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-05-30 12:13:47 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-05-30 12:13:47 0 [Note] /application/mysql//bin/mysqld (mysqld 5.6.36) starting as process 3545 ...
/application/mysql//bin/mysqld: Character set ‘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‘ is not a compiled character set and is not specified in the ‘/application/mysql-5.6.34/share/charsets/Index.xml‘ file
2017-05-30 12:13:47 3545 [ERROR] Aborting
2017-05-30 12:13:47 3545 [Note] Binlog end
2017-05-30 12:13:47 3545 [Note] /application/mysql//bin/mysqld: Shutdown complete
是字符集和字符冲突了,所以编译的时候要把字符和字符集选项都加上,并且要兼容!修改编译参数:
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean/make clean all
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
[root@mysqlserver mysql-5.6.36]#cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.34 \
-DMYSQL_DATADIR=/application/mysql-5.6.34/data\
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.34/tmp/mysql.sock \
-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
[root@mysqlserver mysql-5.6.36]# make && make install
#从上文说明中可以看到数据库启动时会读取/etc/my.cnf,因此有可能会导致无法启动,避免的方法就是使用mysqld_safe启动服务时采用--defaults-file参数指定配置文件,前文已将/etc/my.cnf改名了,所以,就不需要指定参数了,这里是一个坑,读者要注意。
此步骤必须要初始化成功,否则,后面会出现登录不了数据库等各种问题。
设置MySQL启动脚本
[root@mysqlserver scripts]# cd /home/oldboy/tools/mysql-5.6.36
[root@mysqlserver mysql-5.6.36]# pwd
/home/oldboy/tools/mysql-5.6.36
[root@mysqlserver mysql-5.6.36]# cp support-files/mysql.server /etc/init.d/mysqld #<==拷贝mysql启动脚本到mysql的命令路径
[root@mysqlserver mysql-5.6.36]# chmod 700 /etc/init.d/mysqld
[root@mysqlserver mysql-5.6.36]# ls -l /etc/init.d/mysqld
-rwx------. 1 root root 10677 May 30 14:18 /etc/init.d/mysqld
报错:
[root@mysqlserver ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to ‘/application/mysql-5.6.34/data-DMYSQL_UNIX_ADDR=/application/mysql-5.6.34/tmp/mysql.sock/mysqlserver.err‘.
The server quit without updating PID file (/application/mysql-5.6.34/data-DMYSQL_UNIX_ADDR=/application/mysql-5.6.34/tmp/mysql.sock/mysqlse[FAILED]).
解决:
[root@mysqlserver mysql]# cp my-new.cnf /etc/my.cnf
[root@mysqlserver mysql]# cat /etc/my.cnf
[mysqld]
# basedir = .....
datadir = /application/mysql/data
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@mysqlserver mysql]# /etc/init.d/mysqld start
Starting MySQL [ OK ]
[root@mysqlserver mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36 Source distribution
Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.03 sec)
安装完成!
本文出自 “寒雨数据库技术” 博客,谢绝转载!
msyql 编译安装