Linux CentOS 下安装 mysql-8.0.13-linux-glibc2.12-x86_64 安装

98 阅读7分钟

Linux下安装mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

//下载 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
[root@root ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
//解压mysql
[root@root ~]# tar -xJvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz 
……
mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisampack
…… //解压完成
//重命名mysql-8.0.13-linux-glibc2.12-x86_64文件夹为mysql
[root@root ~]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
//将mysql移到/usr/local/ 目录下
[root@root ~]# mv /root/mysql /usr/local/
mv:是否覆盖"/usr/local/mysql"? y
//添加mysql用户组及MySQL用户
[root@root ~]# groupadd mysql
[root@root ~]# useradd -r -g mysql mysql
//设置/usr/local/mysql/文件夹的用户权限
[root@root ~]# cd /usr/local/mysql/
[root@root mysql]# chown -R mysql:mysql ./
//新建MySQL数据存储文件夹
[root@root mysql]# mkdir data
[root@root mysql]# mkdir logs
//初始化mysql数据库,生成默认密码
[root@root mysql]#  bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
2018-12-22T05:24:39.603264Z 0 [Warning] [MY-011070] [Server] 'Disablining --skip-symbolic-links (or equivalent) is the default. Consider notas it' is deprecated and will be removed in a future release.
2018-12-22T05:24:39.603444Z 0 [System] [MY-013169] [Server] /usr/localmysqld 8.0.13) initializing of server in progress as process 27519
2018-12-22T05:24:41.891360Z 5 [Note] [MY-010454] [Server] A temporary ed for root@localhost: ePrOX&p>L52#  //这是初始默认密码
2018-12-22T05:24:43.475923Z 0 [System] [MY-013170] [Server] /usr/localmysqld 8.0.13) initializing of server has completed
[Server] A temporary password is generated for root@localhost: lqs-.d,fN1pB


[root@iZwz9ijcs0cia5xad0sewhZ mysql]#  bin/mysqld --initialize --lower-case-table-names=1 --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
2019-07-01T08:42:30.346859Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 15888
2019-07-01T08:42:33.616199Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: lqs-.d,fN1pB
2019-07-01T08:42:35.006735Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) initializing of server has completed

//设置数据库存储文件夹的用户权限
[root@root mysql]# chown -R root:root ./
[root@root mysql]# chown -R mysql:mysql data
[root@root mysql]# chown -R mysql:mysql logs

 root@localhost: A+?;j7fD%o2y
## 异常安装

 bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决方法:

1.安装numactl软件包

复制代码
[root@testvm01 mysql]# yum -y install numactl
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package numactl.x86_64 0:2.0.9-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                     Arch                                       Version                                          Repository                                       Size
===============================================================================================================================================================================================
Installing:
 numactl                                     x86_64                                     2.0.9-2.el6                                      rhel-source                                      74 k

Transaction Summary
===============================================================================================================================================================================================
Install       1 Package(s)

Total download size: 74 k
Installed size: 171 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : numactl-2.0.9-2.el6.x86_64                                                                                                                                                  1/1 
  Verifying  : numactl-2.0.9-2.el6.x86_64                                                                                                                                                  1/1 

Installed:
  numactl.x86_64 0:2.0.9-2.el6                                                                                                                                                                 

Complete!

sudo yum install libaio
Last metadata expiration check: 19:59:07 ago on Wed 28 Aug 2024 02:21:06 AM CST.
Dependencies resolved.
======================================================================================================
 Package            Architecture       Version                    Repository                     Size
======================================================================================================
Installing:
 libaio             x86_64             0.3.111-13.el9             ol9_baseos_latest              24 k

Transaction Summary
======================================================================================================
Install  1 Package

[root@suven mysql]#  bin/mysqld --initialize --lower-case-table-names=1 --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
2024-08-28T14:22:28.335314Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 13248
2024-08-28T14:22:28.374119Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-08-28T14:22:29.321054Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-08-28T14:22:31.148398Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2024-08-28T14:22:31.148713Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2024-08-28T14:22:31.235679Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: A+?;j7fD%o2y

修改etc/my.cnf配置文件,修改为以下内容:

[root@root ~]# vim /etc/my.cnf

1.第一种
[mysqld]
server-id                      = 1
port                           = 3306
bind-address                   = 0.0.0.0 
max_connections                = 5000
mysqlx_port                    = 33060
mysqlx_socket                  = /tmp/mysqlx.sock
basedir                        = /usr/local/mysql
datadir                        = /usr/local/mysql/data
socket                         = /tmp/mysql.sock
pid-file                       = /tmp/mysqld.pid
slow_query_log                 = ON
slow_query_log_file            = /usr/local/mysql/logs/slow.log
log-error                      = /usr/local/mysql/logs/error.log
long_query_time                = 0.2
log-bin                        = bin.log
relay-log                      = relay.log
binlog_format                  = ROW
relay_log_recovery             = 1
character-set-client-handshake = FALSE
character-set-server           = utf8mb4
collation-server               = utf8mb4_unicode_ci
init_connect                   ='SET NAMES utf8mb4'
innodb_buffer_pool_size        = 1G
join_buffer_size               = 128M
sort_buffer_size               = 2M
read_rnd_buffer_size           = 2M
log_timestamps                 = SYSTEM
lower_case_table_names         = 1
default-authentication-plugin  = mysql_native_password

2.第二种
[client]
port                           = 3306
#socket                         = /usr/local/mysql/mysql.sock

[mysqld]
server-id                      = 1
port                           = 3306
bind-address                   = 0.0.0.0
max_connections                = 5000
max_user_connections           = 4500
#mysqlx_port                    = 33060
basedir                        = /usr/local/mysql
datadir                        = /usr/local/mysql/data

init_connect                   ='SET NAMES utf8mb4'
innodb_buffer_pool_size        = 2048M
join_buffer_size               = 512M
sort_buffer_size               = 2M
read_rnd_buffer_size           = 2M
#log_timestamps                 = SYSTEM
sql_mode ='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'

保存退出。

[root@root mysql]# chmod 777 /etc/my.cnf 
//设置开机自启动
[root@root mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@root mysql]# chmod +x /etc/init.d/mysql 
//注册查看服务
[root@root mysql]# chkconfig --add mysql
[root@root mysql]# chkconfig --list mysql
mysql              0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
//    /etc/ld.so.conf 这个文件记录了编译时使用的动态链接库的路径,告诉链接器去哪个路径下寻找链接时需要用到的库,如果找不到,就会提示链接错误。
如果我们安装了第三方的库,而没有将它放在链接器可以找到的目录,则运行使用这些第三方库的程序时,会提示找不到库。
[root@root mysql]# vim /etc/ld.so.cnf
添加如下内容:
include ld.so.conf.d/*.conf
/usr/local/mysql/lib

配置环境变量
[root@root mysql]# vim /etc/profile
添加如下内容:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
//让配置文件立马生效
[root@root mysql]# source /etc/profile
//启动MySQL服务
重启数据库,并连接数据修,修改初始账号密码
[root@root mysql]# service mysql start
//使用生成的密码登陆MySQL数据库
[root@root mysql]# mysql -u root -p
mysql: [Warning] World-writable config file '/etc/my.cnf' is ignored.
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13
Copyright (c) 2000, 2018, 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 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.13 sec)
mysql>FLUSH PRIVILEGES; 
mysql> exit
重先连接数据库,添加角色账号和角色权限
//退出重登录mysql
[root@root mysql]# mysql -u root -p
mysql: [Warning] World-writable config file '/etc/my.cnf' is ignored.
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
到此安装完成!
这里设置的 /etc/my.cnf 权限是777 ,就是任何人都可读可写,my.cnf 会被忽略掉,mysql的安全机制,也可以不要my.cnf配置文件。
 
下面设置一下MySQL的远程访问
简单写一下命令,自己写的时候忘了记录,网上也是一大堆。
登陆mysql
mysql -u root -p 
use mysql;
select host,user from user;
 
CREATE USER 'root'@'%' IDENTIFIED BY '123456';
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; 
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; 
FLUSH PRIVILEGES; 
 
下面一定要记得关闭防火墙
service iptables stop
 
设置防火墙开机不启动
chkconfig iptables off 
 
然后关机重启,连接试一试吧!
# 不关闭防火墙的话无法使用
1、命令行界面输入命令“systemctl status firewalld.service”并按下回车键。
2、然后在下方可度以查看得到“active(running)”,此时说明防火墙已经被打开了。
3、在命令行中输入systemctl stop firewalld.service命令,进行关闭防火墙。
4、然后再使用命令systemctl status firewalld.service,在下方出现disavtive(dead),这权样就说明防火墙已经关闭。
5、再在命令行中输入命令“systemctl disable firewalld.service”命令,即可永久关闭防火墙。

systemctl stop firewalld.service #关闭
systemctl restart firewalld.service #重启
systemctl status firewalld.service #查看状态
systemctl disable firewalld.service #永久关闭