CENTOS7安装MYSQL80(2024.10.15)
目录
MYSQL社区版本链接:MySQL :: Download MySQL Community Server
清理干净以前的Mysql
先看看有没有服务在启动,有的话先停掉
ps axj | grep mysql
ps axj | grep mariadb //mariadb是mysql中开源出来的一个分支
systemctl stop mysqld
systemctl stop myriadb.service
rpm -qa | grep mysql
输出非空,则代表有Mysql,需要卸载
rpm -qa | grep mariadb
输出非空,则代表有mariadb,需要一起卸载,mariadb和Mysql往往是绑定在一起的,放心卸
rpm -qa | grep mysql | xargs yum -y remove
rpm -qa | grep mariadb | xargs yum -y remove
看yum的源路径里有Mysql吗?应该是没有的
[root@imooc mysql]# ls /etc/yum.repos.d/ -l
total 56
-rw-r--r--. 1 root root 2523 Oct 11 02:38 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Nov 23 2020 CentOS-Base.repo-history
-rw-r--r--. 1 root root 1309 May 21 10:48 CentOS-CR.repo
-rw-r--r--. 1 root root 649 May 21 10:48 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 May 21 10:48 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 May 21 10:48 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 May 21 10:48 CentOS-Sources.repo
-rw-r--r--. 1 root root 9454 May 21 10:48 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 May 21 10:48 CentOS-x86_64-kernel.repo
里面没有mysql
查阅centos系统版本
[root@imooc mysql]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
MYSQL repo源路径
repos源头路径:https://repo.mysql.com/
在该链接里根据系统版本找到mysql80的对应的el7版本
wget下载:
wget https://repo.mysql.com/mysql80-community-release-el7.rpm
本地指令解析一下源
rpm -ivh mysql80-community-release-el7.rpm
看yum的源路径里有Mysql吗?这回有了
[root@imooc mysql]# ls /etc/yum.repos.d/ -l
total 56
-rw-r--r--. 1 root root 2523 Oct 11 02:38 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Nov 23 2020 CentOS-Base.repo-history
-rw-r--r--. 1 root root 1309 May 21 10:48 CentOS-CR.repo
-rw-r--r--. 1 root root 649 May 21 10:48 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 May 21 10:48 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 May 21 10:48 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 May 21 10:48 CentOS-Sources.repo
-rw-r--r--. 1 root root 9454 May 21 10:48 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 May 21 10:48 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 2325 Oct 24 2023 mysql-community-debuginfo.repo
-rw-r--r--. 1 root root 3361 Oct 24 2023 mysql-community.repo
-rw-r--r--. 1 root root 3466 Oct 24 2023 mysql-community-source.repo
安装MYSQL SERVER
yum install -y mysql-community-server
安装后执行:
[root@imooc mysql]# yum list| grep mysql
会输出一大堆东西,代表安装成功
启动MYSQL
[root@imooc mysql]# systemctl start mysqld
[root@imooc mysql]# service mysqld status //获取启动状态,输出如下代表启动成功
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2024-10-15 08:22:29 EDT; 7s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 9825 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 9903 (mysqld)
Status: "Server is operational"
Tasks: 38
CGroup: /system.slice/mysqld.service
└─9903 /usr/sbin/mysqld
Oct 15 08:22:22 imooc systemd[1]: Starting MySQL Server...
Oct 15 08:22:29 imooc systemd[1]: Started MySQL Server.
停下更换my.cnf
[root@imooc mysql]# systemctl stop mysqld
//my.cnf是Mysql的配置文件,非常重要,初始化步骤进行指定
[root@imooc mysql]# mysqld --initialize --default-files='/usr/local/mysql/my.cnf'
[root@imooc mysql]# systemctl start mysqld
[root@imooc mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2024-10-15 08:25:52 EDT; 4s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10163 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10195 (mysqld)
Status: "Server is operational"
Tasks: 38
CGroup: /system.slice/mysqld.service
└─10195 /usr/sbin/mysqld
Oct 15 08:25:50 imooc systemd[1]: Starting MySQL Server...
Oct 15 08:25:52 imooc systemd[1]: Started MySQL Server.
my.cnf内容(可用,但是不确定是不是全对)
[client]
port =3306
socket =/usr/local/mysql/data/mysql.sock
[mysqld]
#SKIP#
skip-grant-tables=1
skip-name-resolve =1
skip-external-locking =1
skip-symbolic-links =1
#GENERAL#
user=mysql
default_storage_engine=InnoDB
character-set-server=utf8
basedir=/usr/local/mysql
bind-address=0.0.0.0
explicit_defaults_for_timestamp=off
socket=/usr/local/mysql/data/mysql.sock
pid-file=/usr/local/mysql/data/mysqld.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#MYISAM#
key_buffer_size=32M
#undo log#
innodb_undo_directory=/usr/local/mysql/undo
innodb_undo_tablespaces=8
#SAFETY#
max_allowed_packet=100M
max_connect_errors=1000000
sysdate_is_now=1
secure-file-priv='/tmp'
#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
binlog_expire_logs_seconds=86400
#replice#
server-id=1001
relay_log=mysqld-relay-bin
gtid_mode=on
enforce-gtid-consistency
log-slave-updates=on
master_info_repository=TABLE
relay_log_info_repository=TABLE
#caches and limits#
tmp_table_sizze=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
join_buffer_size=1M
thread_stack=512K
max_length_for_sort_data=16K
#innodb#
innodb_buffer_pool_size=256M
#innodb_buffer_pool_instance=8
innodb_flush_method=O_DIRECT
innodb_log_buffer_size=16M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
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=64M
innodb_log_files_in_group=2
innodb_data_file_path=ibdata1:256M:autoextend
innodb_rollback_on_timeout=on
#LOGGING#
log_error=/usr/local/mysql/sql-log/mysql-error.log
slow_query_log_file=/usr/local/mysql/sql-log/slowlog.log
重置root账户密码
查初始化时被分配的随机密码是什么
[root@imooc mysql]# cat /var/log/mysqld.log |grep password
2024-10-11T13:49:23.527513Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: m?_3afAtuUsI
2024-10-15T12:22:24.505919Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 76ywL>+eeX.d (这个是对的)
[root@imooc mysql]# cat /var/log/mysqld.log |grep password
2024-10-11T13:49:23.527513Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: m?_3afAtuUsI
2024-10-15T12:22:24.505919Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 76ywL>+eeX.d
[root@imooc mysql]# systemctl start mysqld
[root@imooc mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2024-10-15 08:25:52 EDT; 22min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10163 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10195 (mysqld)
Status: "Server is operational"
Tasks: 37
CGroup: /system.slice/mysqld.service
└─10195 /usr/sbin/mysqld
Oct 15 08:25:50 imooc systemd[1]: Starting MySQL Server...
Oct 15 08:25:52 imooc systemd[1]: Started MySQL Server.
[root@imooc mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.40
Copyright (c) 2000, 2024, 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> alter user 'root'@'localhost' identified by 'my.cnf';
Query OK, 0 rows affected (0.00 sec)
mysql> /q()
-> \q()
Bye
MYSQL社区版本链接:MySQL :: Download MySQL Community Server
原文地址:https://blog.csdn.net/chengxuya/article/details/142962539
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!