mysql 8.0二进制安装
一、先卸载MySQL残留
1、查看mysql安装了哪些东西
[root@ansible opt]# rpm -qa | grep -i mysql
2、卸载查找出来的关于mysql的软件
yum remove *****
3、查看是否卸载完成
[root@ansible opt]# rpm -qa | grep -i mysql
4、查找mysql相关的目录
[root@ansible opt]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib/python2.7/site-packages/ansible/modules/database/mysql
/usr/lib64/mysql
/var/lib/mysql
/var/lib/mysql/mysql
- 备注:
/etc/selinux
下面的是关于selinux和第二个python的mysql模块可以不管
5、删除查找到的相关目录
[root@ansible opt]# rm -rf /usr/lib64/mysql/ /var/lib/mysql/
[root@ansible opt]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib/python2.7/site-packages/ansible/modules/database/mysql
6、删除/etc/my.cnf
和/var/log/mysqld.log
[root@ansible log]# rm -rf /etc/my.cnf /var/log/mysqld.log
- 注意:mysqld.log如果不删除,会导致新安装的mysql无法生成新密码,从而无法登录
7、删除系统上存在的mysql组和mysql用户(如果没有就不用)
[root@ansible mysql8.0]# groups mysql
mysql : mysql
[root@ansible mysql8.0]# userdel mysql
[root@ansible mysql8.0]# groupdel mysql
groupdel: group 'mysql' does not exist
[root@ansible mysql8.0]# groups mysql
groups: mysql: no such user
- 删除mysql的用户之后,他的属组也自动删除了。
二、下载安装包
1、在opt目录下创建mysql文件夹
[root@ansible log]# cd /mnt/ && mkdir mysql && cd mysql
[root@ansible mysql]#
2、使用wget
下载mysql8.0的xz安装包
[root@ansible mysql]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
--2023-04-15 18:47:21-- https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
Resolving dev.mysql.com (dev.mysql.com)... 104.71.161.87, 2600:1417:76:68e::2e31, 2600:1417:76:681::2e31
Connecting to dev.mysql.com (dev.mysql.com)|104.71.161.87|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com//archives/mysql-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz [following]
--2023-04-15 18:47:22-- https://cdn.mysql.com//archives/mysql-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
Resolving cdn.mysql.com (cdn.mysql.com)... 104.99.49.31
Connecting to cdn.mysql.com (cdn.mysql.com)|104.99.49.31|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 490922012 (468M) [text/plain]
Saving to: ‘mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz’
100%[==============================================================================================================================>] 490,922,012 8.14MB/s in 59s
2023-04-15 18:48:21 (7.98 MB/s) - ‘mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz’ saved [490922012/490922012]
三、解压mysql8.0安装包
1、解压
[root@ansible opt]# tar -xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.20-linux-glibc2.12-x86_64/bin/
mysql-8.0.20-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.20-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.20-linux-glibc2.12-x86_64/bin/myisamlog
.....
.....
mysql-8.0.20-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-8.0.20-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql
[root@ansible opt]#
2、重命名解压后的mysql文件夹
[root@ansible opt]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql8.0
3、创建data存储文件
[root@ansible opt]# cd mysql8.0 && mkdir data
四、创建用户和用户组,并赋予权限
1、创建用户和用户组
[root@ansible mysql8.0]# groupadd mysql
[root@ansible mysql8.0]# useradd -g mysql mysql
2、给用户赋予权限
[root@ansible mysql8.0]# chown -R mysql.mysql /opt/mysql8.0
五、初始化MySQL信息
1、切换到mysql8.0安装路径下
[root@ansible mysql8.0]# cd /opt/mysql8.0/bin/
2、初始化MySQL基本信息
[root@ansible bin]# ./mysqld --user=mysql --basedir=/opt/mysql8.0 --datadir=/opt/mysql8.0/data/ --initialize
2023-04-25T08:28:04.307581Z 0 [System] [MY-013169] [Server] /opt/mysql8.0/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 6268
##正在初始化服务器,进程6268
2023-04-25T08:28:04.368515Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
##InnoDB初始化已经启动
2023-04-25T08:28:05.805777Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
##InnoDB初始化已经结束
2023-04-25T08:28:07.830439Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ewioIah9ik;1
##生成临时密码root@localhost:ewioIah9ik;1
六、添加mysqld服务到系统
1、将mysqld服务添加到系统中
[root@ansible mysql8.0]# pwd
/opt/mysql8.0
[root@ansible mysql8.0]# cp -a ./support-files/mysql.server /etc/init.d/mysql
2、授权以及添加服务
[root@ansible mysql8.0]# chmod +x /etc/init.d/mysql
[root@ansible mysql8.0]# chkconfig --add mysql
3、mysql5.7以后就没有my.cnf了,所以我们创建一个。
vim /etc/my.cnf
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password = k0Ui&wV(Z3yt
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
#配置mysql的文件夹 和 mysql data目录
basedir=/opt/mysql8.0
datadir=/opt/mysql8.0/data
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
# binary logging format - mixed recommended
#binlog_format=mixed
# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
- https://blog.youkuaiyun.com/qq_36244623/article/details/102856912 Linux上对于安装mysql5.7.xxx及以上版本没有my.cnf的解决方案
4、设置my.cnf权限
[root@ansible mysql8.0]# chmod 664 /etc/my.cnf
5、启动MySQL服务
[root@ansible mysql8.0]# service mysql start
Starting MySQL.Logging to '/opt/mysql8.0/data/ansible.err'.
. SUCCESS!
-
如果出现下面报错
[root@ansible mysql8.0]# service mysql start MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED])
处理办法:将/var/lock/subsys/下mysql文件删除
rm -rf /var/lock/subsys/mysql
6、查看MySQL服务状态
[root@ansible mysql8.0]# service mysql status
SUCCESS! MySQL running (3262)
7、将mysql命令添加到服务
[root@ansible mysql8.0]# ln -s /opt/mysql8.0/bin/mysql /usr/bin
七、登录MySQL
1、登录密码使用之前随机生成的密码
[root@ansible mysql8.0]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.20
Copyright (c) 2000, 2020, 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>
2、修改管理员密码,其中wei1234是新的密码,按自己的设置。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'wei1234';
Query OK, 0 rows affected (0.02 sec)
3、重新加载缓存,使密码生效。
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4、退出MySQL,使用新密码登录
[root@ansible mysql8.0]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.20 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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>
八、修改mysql配置,使其可以用远程工具登录
mysql> update mysql.user set host='%' where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
-
UPDATE mysql.user set Host = ‘10.37.41.1’ where User = ‘username’; 授权单个ip
查看user表
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)