centos7 安装 mysql8 总结(离线)
目录
2.5 初始化数据库(初始化过程有随机的 root 密码,注意输出信息)
2.8 配置数据库的 sock 文件,并修改 root 用户的初始密码
2.12 mysql的其他命令: 启动,进入,停止, 重启,状态
于使用环境原因, 这里只写离线安装的步骤,本流程在centos7.8上安装成功
1,资源准备
1.1 mysql安装包下载
下载地址:mysql官网
1.2 上传工具下载
XshellXftpPortable
提取码:4dpl
1.3 数据库连接工具
Navicat Premium 12.zip
提取码:l9fg
2,安装与配置
2.0创建用户组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
2.1 上传数据库安装包
通过1.2工具,将包 mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz 上传到 linux 的 “/usr/local”下
2.2 解压
[root@localhost local]# tar -Jxf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
2.3 重命名
重命名解压的目录 mysql-8.0.25-linux-glibc2.12-x86_64 为:mysql
[root@localhost local]# mv mysql-8.0.25-linux-glibc2.12-x86_64 mysql
2.4 修改配置文件
修该配置文件 /etc/my.cnf 内容如下(注意: 完全替换即可,若找不到该文件,可以新建到此位置)
[mysqld]
user=mysql
port = 3306
socket = /var/lib/mysql/mysql.sock
datadir = /var/lib/mysql
character-set-server=utf8
server-id = 1
max_connections = 1000
group_concat_max_len = 102400
max_connect_errors = 10
table_open_cache = 4096
event_scheduler = ON
skip-name-resolve
lower_case_table_names = 1
max_allowed_packet = 64M
binlog_cache_size = 32M
max_heap_table_size = 256M
read_rnd_buffer_size = 64M
sort_buffer_size = 256M
join_buffer_size = 512M
thread_cache_size = 300
log_bin_trust_function_creators=1
key_buffer_size = 256M
read_buffer_size = 32M
read_rnd_buffer_size = 128M
bulk_insert_buffer_size = 512M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
######READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE
transaction_isolation = READ-COMMITTED
tmp_table_size = 512M
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 15
slow_query_log = 1
slow_query_log_file = /var/lib/mysql/slow.log
long_query_time = 5
####### InnoDB
innodb_buffer_pool_size = 512M
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 4
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
#innodb_force_recovery=1
[mysqldump]
quick
max_allowed_packet = 64M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 65535
log-error=/var/lib/mysql/mysqld.log
pid-file=/var/lib/mysql/mysqld.pid
2.5 初始化数据库(初始化过程有随机的 root 密码,注意输出信息)
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
注意此处的系统输出信息中包含系统默认的 root 用户密码,请记录下来
2.6 安装加密算法
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
2.7 启动mysql
在mysql目录下启动:
[root@centos7 mysql]# service mysqld start
Starting MySQL.Logging to '/var/lib/mysql/mysqld.log'.
. SUCCESS!
2.8 配置数据库的 sock 文件,并修改 root 用户的初始密码
[root@centos7 mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@centos7 mysql]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: 此处粘贴2.5 中生成的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> set password = '123456';
Query OK, 0 rows affected (0.01 sec)
若要退出mysql客户端 输入: \q 回车
mysql> \q
Bye
[root@centos7 mysql]#
2.9 配置mysql用户允许远程访问:
创建远程登录对象:CREATE USER 'root'@'%' IDENTIFIED BY '123456';
授权远程登录:grant all privileges on *.* to 'root'@'%' with grant option;
强制刷新:flush privileges;
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2.10 mysql密码模式修改
由于mysql8的密码采用了“caching_sha2_password”模式,而老版的是“mysql_native_password”模式,所以造成很多客户端连接不上,所以可以修改mysql的用密码模式
修改方式如下;
- 在my.cnf 文件中添加:default_authentication_plugin=mysql_native_password 然后重启mysql,新建的用户都是“mysql_native_password”模式的
- 对于安装时已经存在的用户(比如:root)或想给单个用户设定密码模式的可以采用如下命令:
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
2.11 关闭防火墙
用navicat连接看是否可以远程登陆,默认端口为3306,如果不能,则查看防火墙是否开启了该端口。
添加端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent
重载防火墙:firewall-cmd --reload
[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost mysql]# firewall-cmd --reload
2.12 mysql的其他命令: 启动,进入,停止, 重启,状态
进入客户端 : /usr/local/mysql/bin/mysql -uroot -p
启动命令: ./support-files/mysql.server start 或 #service mysqld start
重启命令:./support-files/mysql.server restart 或 #service mysqld restart
停止命令:./support-files/mysql.server stop 或 #service mysqld stop
状态命令: ./support-files/mysql.server status 或 #service mysqld status
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# ./support-files/mysql.server start
Starting MySQL.. SUCCESS!
[root@localhost mysql]# ./support-files/mysql.server restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@localhost mysql]# ./support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!
3,连接测试
可使用1.3中下载的工具对mysql服务器进行连接
参考来自
版权声明:本文为CSDN博主「jackletter」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010476739/article/details/100083959