centos7.6 上mysql8.0的安裝
安裝mysql8.0.16版本
安裝包可以從mysql官網下載,也可以https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/這里下載
刪除原來的數據庫
卸載maridb
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-5.5.60-1.el7_5.x86_64
mariadb-server-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-server-5.5.60-1.el7_5.x86_64
查看是否已經安裝mysql
[root@localhost ~]# rpm -qa | grep -i mysql
akonadi-mysql-1.9.2-4.el7.x86_64
perl-DBD-MySQL-4.023-6.el7.x86_64
qt-mysql-4.8.7-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps akonadi-mysql-1.9.2-4.el7.x86_64
[root@localhost ~]# rpm -e --nodeps perl-DBD-MySQL-4.023-6.el7.x86_64
[root@localhost ~]# rpm -e --nodeps qt-mysql-4.8.7-2.el7.x86_64
刪除mysql文件
[root@localhost ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/root/.virtualenvs/django_env/lib/python3.6/site-packages/django/contrib/gis/db/backends/mysql
/root/.virtualenvs/django_env/lib/python3.6/site-packages/django/db/backends/mysql
/root/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
[root@localhost ~]# rm -rf /val/lib/mysql
[root@localhost ~]# rm -rf /usr/lib/mysql
[root@localhost ~]# rm -rf /usr/lib64/mysql
刪除配置文檔
rm -rf /etc/my.cnf
再次查找機器是否安裝mysql
rpm -qa|grep -i mysql
關閉Selinux
# 臨時關閉
setenforce 0
# 永久關閉
vim /etc/sysconfig/selinux
SELINUX=enforcing 改為 SELINUX=disabled
重啟服務reboot
安裝mysql依賴包(選做)
yum -y install libaio.so.1 libgcc_s.so.1 libstdc++.so.6
yum update libstdc++-4.4.7-4.el6.x86_64
yum search libaio # 檢索相關信息
yum install libaio # 安裝依賴包
yum install net-tools
第一種安裝方式 rpm包
# 安裝包
mysql-community-client-8.0.17-1.el7.x86_64.rpm
mysql-community-common-8.0.17-1.el7.x86_64.rpm
mysql-community-libs-8.0.17-1.el7.x86_64.rpm
mysql-community-server-8.0.17-1.el7.x86_64.rpm
# 按照順序安裝
rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.17-1.el7.x86_64.rpm
可能的報錯解決方案
報錯1
error: Failed dependencies: /usr/bin/perl is needed by
mysql-community-server-8.0.11-1.el7.x86_64 perl(Getopt::Long) is
needed by mysql-community-server-8.0.11-1.el7.x86_64 perl(strict)
解決1
yum install perl
報錯2
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.11-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.11-1.el7.x86_64
解決2
wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
rpm -ivh http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
初始mysqld –initialize啟動數據庫
mysqld --initailize --user=mysql
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld
報錯
[root@localhost mysql]# mysqld --initailize
2019-07-28T08:06:16.454284Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 17757
2019-07-28T08:06:16.457257Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2019-07-28T08:06:16.457292Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-07-28T08:06:16.457404Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.17) MySQL Community Server - GPL.
# 解決方案
vim /etc/my.cnf
user=mysql
port=3306
mysqld --initailize --user=mysql
systemctl start mysqld.service
2019-07-28T08:08:22.699288Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.17) MySQL Community Server - GPL.
2019-07-28T08:10:21.874694Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 18083
2019-07-28T08:10:21.884794Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 13 in a file operation.
2019-07-28T08:10:21.884807Z 1 [ERROR] [MY-012595] [InnoDB] The error means mysqld does not have the access rights to the directory.
2019-07-28T08:10:21.884818Z 1 [ERROR] [MY-012270] [InnoDB] os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2019-07-28T08:10:21.884830Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2019-07-28T08:10:21.885164Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-07-28T08:10:21.885227Z 0 [ERROR] [MY-010119] [Server] Aborting
# 解決
ll /var/run/mysqld/
# 不存在
mkdir -p /var/run/mysqld/
chown -R mysql:mysql /var/run/mysqld
# 如果還報錯,則進入下一步。
# 關閉selinux.並重啟。
setenforce 0
# 重啟服務
service mysqld restart
systemctl status mysqld.service
開機啟動服務設置
systemctl enable mysqld
查看初始化密碼
# 命令查看數據庫的密碼
cat /var/log/mysqld.log | grep password
第二種mysql安裝方式(建議使用這一種)
userdel mysql
# 增加mysql用戶組,用戶
groupadd mysql
useradd -g mysql mysql
tar xf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
mkdir data sql_log undo_log
chown mysql:mysql -R data/ sql_log/ undo_log/
vim /etc/profile
export PATH=$PATH:/usr/localmysql/bin
source /etc/profile
# 拷貝my.cnf的下方內容
vim /etc/my.cnf
:%s@/home/mysql@/usr/local/mysql@
# 初始化
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 拷貝啟動程序
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
# 啟動服務
/etc/init.d/mysqld start
# 報錯
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data//localhost.localdomain.pid).
檢查my.cnf中路徑配置是否有誤前面創建的三個文件夾是否一致,文件夾用戶組是否屬於mysql
# 查詢密碼:
[root@localhost sql_log]# grep password mysql-error.log
2019-07-28T10:50:16.286737Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: du%3pH5VBo;l
# 登錄mysql
mysql -uroot -p
# 可以看到版本號為8.0.17
[root@localhost sql_log]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
# 修改密碼
alter user user() identified by '123456';
my.cnf配置文件
[client]
port=3306
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
# Skip #
skip_name_resolve= 1
skip-external-locking=1
symbolic-links= 0
# GENERAL #
user = mysql
default_storage_engine=InnoDB
character-set-server=utf8
socket=/usr/local/mysql/data/mysql.sock
pid_file=/usr/local/mysql/data/mysqld.pid
basedir = /usr/local/mysql
#log_error=/usr/local/mysql/sql_log/mysql_1302.err
port=3306
bind-address=0.0.0.0
explicit_defaults_for_timestamp=off
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql_mode=NO_ENGINE_SUBSTITUTION
#read_only=on
# MyISAM #
key_buffer_size=32M
#myisam_recover=FORCE,BACKUP
# undo log #
innodb_undo_directory=/usr/local/mysql/undo_log
innodb_undo_tablespaces=16
# SAFETY #
max_allowed_packet=100M
max_connect_errors=1000000
sysdate_is_now=1
#innodb = FORCE
#innodb_strict_mode=1
secure-file-priv=/usr/local/mysql/sql_log
default_authentication_plugin='mysql_native_password'
# Replice #
server-id=1306
relay_log=mysqld-relay-bin
gtid_mode=on
enforce-gtid-consistency
log-slave-updates=on
master_info_repository=TABLE
relay_log_info_repository=TABLE
# group replication specific options
#plugin-load=group_replication.so
#group_replication=FORCE_PLUS_PERMANENT
#transaction-write-set-extraction=XXHASH64
#loose-group_replication_start_on_boot=ON
#loose-group_replication_bootstrap_group=OFF
#loose-group_replication_group_name='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
#group_replication_local_address='10.102.13.2:33061'
#group_replication_group_seeds='10.102.13.3:33061,10.102.13.5:33061'
# DATA STORAGE #
datadir=/usr/local/mysql/data/
tmpdir=/tmp
# BINARY LOGGING #
log_bin=/usr/local/mysql/sql_log/mysql-bin
max_binlog_size=1000M
binlog_format=row
expire_logs_days=7
# sync_binlog=1
# CACHES AND LIMITS #
tmp_table_size = 32M
max_heap_table_size = 32M
max_connections = 4000
thread_cache_size = 2048
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 4096
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
# thread_concurrency = 24
join_buffer_size = 1M
# table_cache = 32768
thread_stack = 512k
max_length_for_sort_data = 16k
# INNODB #
innodb_flush_method = O_DIRECT
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
innodb_buffer_pool_size = 2G
#innodb_buffer_pool_instances = 8
innodb_stats_on_metadata = off
innodb_open_files = 8192
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_io_capacity = 20000
innodb_thread_concurrency = 0
innodb_lock_wait_timeout = 60
innodb_old_blocks_time=1000
innodb_use_native_aio = 1
innodb_purge_threads=1
innodb_change_buffering=all
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_rollback_on_timeout=on
# LOGGING #
log_error=/usr/local/mysql/sql_log/mysql-error.log
# log_queries_not_using_indexes = 1
# slow_query_log = 1
slow_query_log_file=/usr/local/mysql/sql_log/slowlog_1305.log
# TimeOut #
#interactive_timeout = 30
#wait_timeout = 30
#net_read_timeout = 60
[mysqldump]
quick
max_allowed_packet = 100M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout