CentOS 源码安装MySQL5.7
一、安装方式
源码安装,源码包名称mysql-boost-5.7.27.tar.gz,此版本包含boost库,在解压后的boost路径下。安装时,可以-ddownload_boost=1 -dwith_boost=/usr/local/mysql-5.7.27/boost/指定boost路径
二、安装路径
基础路径 /usr/local/mysql
数据文件路径 /usr/local/mysql/data
三、安装依赖
yum -y install autoconf automake libtool cmake ncurses-devel openssl-devel lzo-devel zlib-devel gcc gcc-c++
四、添加用户信息
添加系统mysql组和mysql用户
添加系统mysql组 groupadd mysql
添加mysql用户 useradd -r -g mysql mysql (添加完成后可用id mysql查看)
切到mysql目录 cd /usr/local/mysql
修改当前目录拥有者为mysql用户 chown -r mysql.mysql ./
五、配置预编译
cmake . -dcmake_install_prefix=/usr/local/mysql -dmysql_datadir=/usr/local/mysql/data -dsysconfdir=/etc -dwith_innobase_storage_engine=1 -dwith_archive_storage_engine=1 -dwith_blackhole_storage_engine=1 -dwith_partition_storage_engine=1 -dwith_perfschema_storage_engine=1 -dwithout_example_storage_engine=1 -dwithout_federated_storage_engine=1 -ddefault_charset=utf8 -ddefault_collation=utf8_general_ci -dwith_extra_charsets=all -denabled_local_infile=1 -dwith_readline=1 -dmysql_unix_addr=/usr/local/mysql/mysql.sock -dmysql_tcp_port=3306 -dmysql_user=mysql -dcompilation_comment="lq-edition" -denable_dtrace=0 -doptimizer_trace=1 -dwith_debug=1 -ddownload_boost=1 -dwith_boost=/usr/local/mysql-5.7.27/boost/
出现如下警告
cmake warning:
manually-specified variables were not used by the project:
mysql_user
with_readline
-- build files have been written to: /usr/local/mysql-5.7.27
忽略即可。
六、编译和安装
编译 make
安装 make install
如果服务器内存较小,可以使用如下指令
make -j `grep processor /proc/cpuinfo | wc -l` #编译时会消耗很大内存,小内存可能无法编译完成
七、初始化数据库
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql
获取到密码 ,/7xa7y#hn_x
八、开启ssl功能
cd /usr/local/mysql/bin/
./mysql_ssl_rsa_setup
九、测试启动mysql
cd /usr/local/mysql/bin/
./mysqld_safe --user=mysql
出现如下错误
mysqld_safe error:log-error set to '/var/log/mariadb/mariadb.log',however file does not exists,create writable for you 'mysql'.
是mysql用户没有/var/log/mariadb/mariadb.log权限
执行如下操作
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -r mysql:mysql /var/log/mariadb
从新执行./mysqld_safe --user=mysql
执行成功
十、启动mysql服务并更改密码
cd /usr/local/mysql/support-files
./mysql.server start
上述方法一直报错,因为创建mysql用户的使用使用了chown -r mysql:mysql ./来配置/user/local/mysql目录的所属路径,但是该方法应该是ubuntu的指令,所以导致安装的时候数据库的权限出了问题,centos的指令应该是chown -r mysql.mysql ./,第四步已经更正,这里应该不会再出现此错误,如果还是出现此错误,按照如下方式操作。
这里为了正常启动数据库,而不用重装,采用如下方式
配置/etc/my.cnf文件如下
[mysqld]
datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/usr/local/mysql/mysql.sock
# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# settings user and group are ignored when systemd is used.
# if you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
然后执行如下指令,以root权限启动数据库
cd /usr/local/mysql/bin
./mysqld --user=root
十一、配置文件位置
/etc/my.cnf
十二、修改密码
set password for 'root'@'%' = password('password');
十三、添加环境变量
编辑 ~/.bashrc文件,vim ~/.bashrc,添加如下内容
export mysql_home=/usr/local/mysql
export path=$path:$mysql_home/bin
执行如下指令,使环境变量生效
source ~/.bashrc
十四、运行数据库远程连接
执行下面命令
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
刷新权限表
flush privileges;
create database if not exists test_db default charset utf8 collate utf8_general_ci;
–uroot –ppassword –dtest_db
上一篇: js常见面试题
下一篇: 智能建站怎么样?智能建站优势有哪些?