这里我们直接讲第二个实例如何去部署和启动
目录
1 解压,改变属组。
前面讲了很多次了,我们到解压后的目录下查看:
[root@bgsbtsp0006-dqf:mysql]# ls
bin include LICENSE man mysqld.log mysql.sock README share support-files
docs lib LICENSE.router my.cnf mysqld.pid mysql.sock.lock README.router slow-query.log
2 查看my.cnf文件
[mysqld]
datadir=/opt/data/mysql_data
basedir=/opt/mysql
socket=/opt/mysql/mysql.sock
log-bin=mysql-bin
port=3308
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# character set
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# Default user
user=mysql
# slow query
slow_query_log=on
slow_query_log_file=/opt/mysql/slow-query.log
[client]
port=3308
[mysqld_safe]
log-error=/opt/mysql/mysqld.log
pid-file=/opt/mysql/mysqld.pid
3 初始化数据库
[root@bgsbtsp0006-dqf:mysql]# cd /opt/mysql
[root@bgsbtsp0006-dqf:mysql]# ./bin/mysqld --defaults-file=/opt/mysql/my.cnf --initialize --user=mysql --datadir=/opt/data/mysql_data --basedir=/opt/mysql
2019-05-07T14:19:04.176339Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-05-07T14:19:04.176423Z 0 [Warning] [MY-010915] [Server] '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.
2019-05-07T14:19:04.176545Z 0 [System] [MY-013169] [Server] /opt/mysql-8.0.15-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.15) initializing of server in progress as process 3234346
2019-05-07T14:19:06.673708Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uezlg3wTd;hE
2019-05-07T14:19:07.946358Z 0 [System] [MY-013170] [Server] /opt/mysql-8.0.15-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.15) initializing of server has completed
4 启动服务:
[root@bgsbtsp0006-dqf:bin]# ./mysqld_safe --defaults-file=/opt/mysql/my.cnf &
[1] 3234859
2019-05-07T14:20:01.711819Z mysqld_safe Logging to '/opt/mysql/mysqld.log'.
2019-05-07T14:20:01.744338Z mysqld_safe Starting mysqld daemon with databases from /opt/data/mysql_data
[root@bgsbtsp0006-dqf:bin]# netstat -tunlp|grep 3308
tcp6 0 0 :::3308 :::* LISTEN 3235093/mysqld
5 客户端连接
[root@bgsbtsp0006-dqf:mysql]# ./bin/mysql -uroot -puezlg3wTd;hE -S /opt/mysql/mysql.sock
6 修改密码和远程登陆连接
前面也有讲过,这里不再赘述
7 FAQ
1 mysqld.log不存在
2019-05-07T14:10:28.623220Z mysqld_safe error: log-error set to '/opt/mysql/mysqld.log', however file don't exists. Create writable for user 'mysql'.
解决方案:
# 既然报日志文件不存在,我们就创建一下
touch /opt/mysql/mysqld.log
2. 启动失败
2019-05-07T14:19:27.113350Z mysqld_safe A mysqld process already exists
解决方案:
# 用下面的指令去启动 不要用mysql.server start否则会报上述错误
./mysqld_safe --defaults-file=/opt/mysql/my.cnf &