centos 7.5安装mysql5.7.17

2020-07-21 15:44:28 浏览数 (1)

准备环境和安装包

linux :centos 7.5

mysql 二进制压缩包

压缩包连接:https://downloads.mysql.com/archives/community/

1、确认本地是否有安装maridb,如果有的话先卸载掉

rpm -qa | grep Mariabd

yum remove -nodeps -y maridb-xxx

2、本地环境清理干净后,创建相关目录

(官方默认目录:/usr/local/mysql)

mysql存放数据目录:mkdir dbdata

应用数据存储目录:mkdir appdata

binlog日志存储目录:mkdir dbbinlog

3、添加mysql用户/用户组

useradd mysql

groupadd mysql

给以上三个目录分别分配用户和用户组

4、解压mysql5.7安装包

tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

解压后如下,然后给这个目录创建一个软连接,用于后续使用此文件

5、设置环境变量

vim /etc/profile

export PATH=/data/dbdata/mysql/bin:$PATH

source /etc/profile

mysql -V 验证下

6、初始化mysql

mysqld --initialize-insecure --user=mysql --basedir=/data/appdata/mysql --datadir=/data/dbdata/

6.1、初始化语句扩展

mysqld --initialize-insecure:不会生成密码,直接空密码登录,建议无密码初始化

mysqld --initialize:这个参数会随机生成一个密码,需要到日志里面去查(应该是在mysqld.err日志里面)

我这里执行后报错了,如图

这里是由于我的path路径写错了

修改后初始化成功

注意:这里一般最常见的错误大概如下

6.1、

mysqld: error while loading shared libraries: libaio.so.q:

cannot open shared object file: no such file or directory

解决方法:yum install -y libaio-devel

6.2、

2020-07-21T04:53:03.990092Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-07-21T04:53:03.991746Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

2020-07-21T04:53:03.991774Z 0 [ERROR] Aborting

解决办法:清理datadir目录

rm -rf /data/dbdata/*

7、配置my.cnf配置文件

[mysqld]

user=mysql

basedir=/data/appdata/mysql

datadir=/data/dbdata

server_id=101

port=3306

socket=/tmp/mysql.sock

[mysql]

socket=/tmp/mysql.sock

8、启动mysqld服务

service mysqld start 或者 systemctl start mysql.service

启动报错,如下

/data/appdata/mysql/bin/mysqld_safe: line 586: /usr/local/mysql/data/mysqld_safe.pid: No such file or directory

awk: (FILENAME=- FNR=1) warning: error writing standard output (Broken pipe)

2020-07-21T07:02:57.447677Z mysqld_safe Logging to '/usr/local/mysql/data/VM-48-17-centos.err'.

Logging to '/usr/local/mysql/data/VM-48-17-centos.err'.

2020-07-21T07:02:57.451028Z mysqld_safe The file /usr/local/mysql/bin/mysqld

does not exist or is not executable. Please cd to the mysql installation

directory and restart this script from there as follows:

./bin/mysqld_safe&

See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

解决方法:

因为mysqld_safe启动脚本默认的从/usr/local/mysql目录中读取另外一个启动脚本mysqld,因为我的安装目录为

/data/appdata/msyql,所以报错如上

这里可以根据报错来做下这个路径的软连接来解决

mkdir -p /usr/local/mysql/bin

ln -s /data/appdata/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

然后再次启动服务可以了

延伸:如果是mysql 5.6 安装包,安装步骤没有区别,只是在初始化的时候执行语句不一样

/data/appdata/mysql/scripts/mysql_instll_db --user=mysql --basedir=/data/appdata/mysql --datadir=/data/dbdata/

0 人点赞