1. 要对MySQL数据库清除原来已有的数据,重新初始化数据库。
Linux系统:CentOS7.6,数据库:MySQL5.6.40。先将mysql进程强行停止掉。
pkill mysqld
2. 对数据库进行清理:
[root@mv172 ~]# rm -rf /application/mysql/data/*
[root@mv172 ~]# \rm -rf /data/mysql/*
3. 配置文件安装在/application/mysql-5.6.40/my.***f
[mysqld]
basedir=/application/mysql
datadir=/application/mysql/data
socket=/tmp/mysql.sock
log_error=/var/log/mysql.log
log_bin=/data/mysql/mysql-bin
binlog_format=row
skip-name-resolve
server_id=172
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[client]
socket=/tmp/mysql.sock
4. 执行数据库初始化命令: 这次初始化没有把配置文件添加进去,导致问题的开始。
[root@mv172 ~]# /application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/
......出现一堆的执行代码,此处就省略:
5. 将mysql启动复制到系统为默认启动路径
[root@mv172 ~]# \cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
6. # 启动mysql,这时候有报错:
[root@mv172 ~]# /etc/init.d/mysqld start
/etc/init.d/mysqld: line 244: my_print_defaults: ***mand not found
/etc/init.d/mysqld: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
7. 经过不断尝试,终于找到问题根源。 因为起初 初始化时,没有将mysql路径和数据库保存路径绑定好,而导致一连串问题。
查配置文件,没有配置的保存mysql-bin二进制保存路径。
[root@mv172 /]# mkdir -p /data/mysql
[root@mv172 /]# chown -R mysql.mysql /data/*
8. 重新初始化数据,自此增加“--defaults-file=/application/mysql/my.***f”
[root@mv172 data]# /application/mysql/scripts/mysql_install_db --defaults-file=/application/mysql/my.***f --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
9 . # 于是查看mysqld文件
发现
“basedir=
datadir=”
这两个路径,突然想到mysql启动顺手时以这个mysqld优先,于是将配置文件这两个路径添加到这里来,
# [mysqld]
# basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.***f, ~/.my.***f or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=
datadir=
......
10 . 重新再执行初始化数据库,执行
启动数据库命令
[root@mv172 data]# /etc/init.d/mysqld start
Starting MySQL.. SU***ESS!