安装编译
下载源码
mysql-5.7.14.tar.gz
解压定义安装变量
cd /usr/local/src
mysql_version="mysql-5.7.14"
tar -zxf "${mysql_version}.tar.gz"
cd ${mysql_version}
配置
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/services/${mysql_version} \
-DMYSQL_DATADIR:PATH=/data/${mysql_version} \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DMYSQL_USER=mysql \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=yes
报错:
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
This CMake script will look for boost in . If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:455 (INCLUDE)
解决:
mysql 依赖boost,添加编译选项:
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/services/boost
备注:
- cmake 生成的临时文件是CMakeCache.txt, 需要删除掉之前配置生成的临时文件
rm CMakeCache.txt
- 重新进行配置检查,避免由于,更新系统软件包后,依然使用旧的临时文件,导致配置找不到相关的库。
安装
make
make install
配置启动
以下操作用户均为root
创建用户,数据库初始化
# 创建mysql运行用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
# 创建mysql数据目录,并授权
mkdir -p /data/${mysql_version}
chown -R mysql:mysql /usr/local/services/${mysql_version}
chown -R mysql:mysql /data/${mysql_version}
# 初始化mysql 系统数据表
# /usr/local/services/${mysql_version}/bin/mysqld \
--initialize \
--user=mysql \
--datadir=/data/${mysql_version}
2016-08-02T14:27:01.183217Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-02T14:27:01.183281Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-08-02T14:27:01.183289Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-08-02T14:27:02.931391Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-08-02T14:27:03.297417Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-08-02T14:27:03.488097Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2e93cf2d-58bd-11e6-8ed6-94de801a0a56.
2016-08-02T14:27:03.519545Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-08-02T14:27:04.091878Z 0 [Warning] CA certificate ca.pem is self signed.
2016-08-02T14:27:04.223888Z 1 [Note] A temporary password is generated for root@localhost: _bfdDjzhw0ru
# 创建配置文件
mkdir -p /usr/local/services/${mysql_version}/etc/
cp /usr/local/services/${mysql_version}/support-files/my-default.cnf /usr/local/services/${mysql_version}/etc/my.cnf
/usr/local/services/${mysql_version}/bin/mysql_ssl_rsa_setup
# 设置权限
chown -R root /usr/local/services/${mysql_version}
chown -R mysql /data/${mysql_version}
注意:
- 配置文件 etc/my.cnf 需要配置完全,包括安装目录,数据存储目录,等...
- 初始化数据库表,
mysql-5.7.6
之后发生了变更,之前是 mysql_init_db - 若使用etc/my.cnf 中的配置,则需将/etc/my.cnf 中的相关的配置项注释掉
启动mysql
/usr/local/services/${mysql_version}/bin/mysqld_safe --user=mysql &
注意:
无需指定--default-file=$basedir/etc/my.cnf,mysql 有默认的配置文件加载顺序
/etc/my.cnf
basedir/etc/my.cnf
连接mysql
mysql -uroot -p
注意:
若提示无法使用xx.sock,这是因为没有指定连接的sock,可配置my.cnf,指定连接的sock
[client]
socket=/data/${mysql_version}/mysql.sock
更新root密码
update mysql.user set password=password('123456') where user='root';
报错:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决:
SET PASSWORD = PASSWORD('123456');
关闭mysql
/usr/local/services/${mysql_version}/bin/mysqladmin shutdown -uroot -p
设置启动项
cp support-files/mysql.server /etc/init.d/mysql.server
参考:
- http://stackoverflow.com/questions/33467337/reset-mysql-root-password-using-alter-user-statement-after-install-on-mac