Centos7.3中安装MySQL5.7

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7.3中安装MySQL5.7相关的知识,希望对你有一定的参考价值。

首先安装相关环境包

yum -y install
ncurses
ncurses-devel
bison
cmake
gcc gcc-c++

添加mysql程序用户

useradd -s /sbin/nologin mysql

解压软件包

tar zxvf mysql-5.7.17.tar.gz -C /opt/
tar zxvf boost_1_59_0.tar.gz -C /usr/local/ 解压c++运行库
cd /usr/local/
mv boost_1_59_0 boost 重命名,方便管理

cd mysql-5.7.17/

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost -DWITH_SYSTEMD=1
  • 注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧。

make && make install

chown -R mysql.mysql /usr/local/mysql/

vi /etc/my.cnf

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

更改MySQL用户属主属组

chown mysql:mysql /etc/my.cnf

添加环境变量

echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile
echo ‘export PATH‘ >> /etc/profile
source /etc/profile

cd /usr/local/mysql/

bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

复制服务启动脚本

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306

systemctl enable mysqld 设置开机自启动

设置mysql登录用户账户

mysqladmin -u root -p password "abc123" //给root账号设置密码为abc123提示输入的是原始密码。

mysql -u root -p

授权远程登录

grant all privileges on . to ‘root‘@‘%‘ identified by ‘abc123‘ with grant option;

以上是关于Centos7.3中安装MySQL5.7的主要内容,如果未能解决你的问题,请参考以下文章

在centos6.5中安装mysql5.7

CentOS7中安装MySQL5.7

CentOS7中安装MySQL5.7

CentOS7.7中安装MySQL5.7教程(超详细)

Linux(CentOS6.5)中安装mysql5.7

CentOS7中安装与配置MySQL5.7数据库