mysql作为目前最流行的开源数据库之一,其强大的数据库引擎及其安全性等功能的增强,目前已经作为众多软件厂商及中小公司首选,下面介绍下如何快速安装mysql8.
1、下载数据库软件
访问mysql官方网站进行mysql的下载,https://dev.mysql.com/downloads/mysql/,根据自己的实际情况下载所需的数据库版本。
2、创建mysql 8.0.13相关目录;
[root@prod-mysql8-01 app]# mkdir -p /app/mysql8.0.13/logs
[root@prod-mysql8-01 app]# mkdir -p /data/mysql8.0.13/bin-logs
[root@prod-mysql8-01 app]# mkdir -p /data/mysql8.0.13/data
3、创建mysql及mysql组信息
[root@prod-mysql8-01 app]# groupadd -g 530 mysql
[root@prod-mysql8-01 app]# useradd -u 530 mysql -g mysql
4、将目录赋权给mysql用户及组
[root@prod-mysql8-01 app]# chown -R mysql:mysql /app/mysql8.0.13/
[root@prod-mysql8-01 app]# chown -R mysql:mysql /data/mysql8.0.13/
5、mysql tar包安装
[root@prod-mysql8-01 ~]# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar
[root@prod-mysql8-01 ~]# tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
将mysql文件拷贝到对应程序目录下
[root@prod-mysql8-01 ~]# mv mysql-8.0.13-linux-glibc2.12-x86_64/* /app/mysql8.0.13/
修改文件权限
[root@prod-mysql8-01 mysql8.0.13]# chown -R mysql:mysql *
6、初始化数据库
[root@prod-mysql8-01 bin]# /app/mysql8.0.13/bin/mysqld --initialize --user=mysql --basedir=/app/mysql8.0.13/ --datadir=/data/mysql8.0.13/data/
A temporary password is generated for root@localhost: iw_himiXQ5YK
password is generated for root@localhost: 2w;X_toP>fo)
7、mysql注册服务
[root@prod-mysql8-01 support-files]# vi /app/mysql8.0.13/support-files/mysql.server
修改 basedir和datadir
basedir=/app/mysql8.0.13
datadir=/data/mysql8.0.13/data
[root@prod-mysql8-01 support-files]# cp /app/mysql8.0.13/support-files/mysql.server /etc/init.d/mysql
[root@prod-mysql8-01 support-files]# chkconfig --add mysql
[root@prod-mysql8-01 support-files]# chkconfig mysql on
8、修改环境变量
[root@prod-mysql8-01 logs]# echo 'export PATH=/app/mysql8.0.13/bin:$PATH' >> /etc/profile
[root@prod-mysql8-01 logs]# source /etc/profil
9、配置mysql配置文件,/etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
server-id = 131
port = 3306
user = mysql
socket = /tmp/mysql.sock
bind_address = 0.0.0.0
skip_name_resolve = 1
datadir = /data/mysql8.0.13/data
transaction_isolation = READ-COMMITTED
tmp_table_size = 67108864
tmpdir = /tmp
default-time_zone = '+8:00'
character-set-server = utf8mb4
max_allowed_packet = 16777216
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
log_error = /app/mysql8.0.13/logs/error.log
slow_query_log = 1
slow_query_log_file = /app/mysql8.0.13/logs/slow.log
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 10
long_query_time = 5
min_examined_row_limit = 100
innodb_file_per_table = 1
innodb_data_home_dir = /data/mysql8.0.13/data
innodb_log_group_home_dir = /data/mysql8.0.13/data
wait_timeout=600
interactive_timeout=600
max_connections=16000
open_files_limit =80000
innodb_buffer_pool_size = 256m
max_connect_errors=10000
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
default-character-set=utf8mb4
[mysqlhotcopy]
interactive-timeout
10、启动mysql数据库
[mysql@prod-mysql8-01 logs]$ service mysql start
Starting MySQL..... SUCCESS!
[mysql@prod-mysql8-01 logs]$
11、修改root密码
alter user root@'localhost' identified with mysql_native_password by '123456';
启动过程报错找不到error.log文件
[root@prod-mysql8-01 scripts]# service mysql start
Starting MySQL.2020-07-14T05:04:10.974561Z mysqld_safe error: log-error set to '/app/mysql8.0.13/logs/error.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/data/mysql8.0.13/data/prod-mysql8-01.pid).
[root@prod-mysql8-01 scripts]# su - mysql
[mysql@prod-mysql8-01 ~]$ cd /app/mysql8.0.13/logs/
[mysql@prod-mysql8-01 logs]$ ll
total 0
以mysql的身份创建一个文件即可
[mysql@prod-mysql8-01 logs]$ touch error.log
修改配置文件为
innodb_data_home_dir = /data/mysql8.0.13/data
innodb_data_file_path = ibdata1:12M;ibdata2:100M:autoextend
修改完以上内容,数据库则可以正常启动。
文章评论