编译安装mysql56
编译
# linux下用cmake编译安装mysql-5.6.35
# 安装cmake
sudo pacman -S cmake
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz
tar zxvf mysql-5.6.35.tar.gz
cd mysql-5.6.35
# 创建数据存放目录
mkdir -p /vhs/mysql/mysql56
# 创建用户及用户组并指定之上的目录,用户及用户组
sudo useradd -M mysql -s /sbin/nologin
sudo chown -R mysql.mysql /vhs/mysql/mysql56
# 预编译
cmake \
-DCMAKE_INSTALL_PREFIX=/vhs/mysql/mysql56 \
-DMYSQL_DATADIR=/vhs/mysql/mysql56 \
-DSYSCONFDIR=/vhs/mysql/mysql56/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/vhs/mysql/mysql56/tmp/mysqld.sock \
-DWITH_DEBUG=0
# 说明
# 官方https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
-DCMAKE_INSTALL_PREFIX=dir_name 设置mysql安装目录
-DMYSQL_UNIX_ADDR=file_name 设置监听套接字路径,这必须是一个绝对路径名。默认为/tmp/mysql.sock
-DDEFAULT_CHARSET=charset_name 设置服务器的字符集。缺省情况下,MySQL使用latin1的(CP1252西欧)字符集。cmake/character_sets.cmake文件包含允许的字符集名称列表。
-DDEFAULT_COLLATION=collation_name 设置服务器的排序规则。
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
存储引擎选项:MyISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。
静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1
可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema)
-DMYSQL_DATADIR=dir_name 设置mysql数据库文件目录
-DMYSQL_TCP_PORT=port_num 设置mysql服务器监听端口,默认为3306
-DENABLE_DOWNLOADS=bool 是否要下载可选的文件。例如,启用此选项(设置为1),cmake将下载谷歌所使用的测试套件运行单元测试。
# 编译
make -j8
# 编译出错(自行安装所需软件),然后删除下面文件,继续重新编译安装。
rm -rf CMakeCache.txt
make
# 安装
sudo make install
配置
# 初始化权限
# 进入/vhs/mysql/mysql56/
sudo scripts/mysql_install_db --user=mysql --basedir=/vhs/mysql/mysql56/ --datadir=/vhs/mysql/mysql56/
# 修改my.cnf,如下面
nano my.cnf
# 创建
sudo mkdir /vhs/mysql/mysql56/tmp
sudo chmod 777 /vhs/mysql/mysql56/tmp
touch /vhs/mysql/mysql56/tmp/mysqld.pid
touch /vhs/mysql/mysql56/tmp/mysqld.log
# touch /vhs/mysql/mysql56/tmp/mysqld.sock
# chmod 777 /vhs/mysql/mysql56/tmp/mysqld.sock
# 启动数据库
# 测试的时候使用
bin/mysqld_safe &
# 已经调试完毕,请使用服务的方式启动,便于管理 (start stop restart)
sudo support-files/mysql.server start
# 修改mysql用户登录密码为root
sudo bin/mysqladmin -uroot password root
bin/mysql -uroot -proot
# 其他登录
bin/mysql -u root -p
# 注册到系统服务
# 常见错误
sudo cp support-files/mysql.server /etc/init.d/mysqld
# Warning: World-writable config file '/vhs/mysql/mysql56/my.cnf' is ignored
# Warning: World-writable config file '/vhs/mysql/mysql56/my.cnf' is ignored
# .. * The server quit without updating PID file (/vhs/mysql/mysql56/DESKTOP-F6LVIR9.pid).
# my.cnf文件权限644
my.cnf文件
[client]
port = 3306
socket = /vhs/mysql/mysql56/tmp/mysqld.sock
[mysqld]
port = 3306
bind-address = 0.0.0.0
socket = /vhs/mysql/mysql56/tmp/mysqld.sock
server_id =1
datadir = /vhs/mysql/mysql56/
#slow_query_log = 1
#慢查询时间 超过1秒则为慢查询
#long_query_time = 2
#slow_query_log_file = /var/log/mysql/slow.log
user=mysql
[mysqld_safe]
log-error=/vhs/mysql/mysql56/tmp/mysqld.log
pid-file=/vhs/mysql/mysql56/tmp/mysqld.pid