[root@My-Server ~]# rpm -qa | grep mysql
[root@My-Server ~]# whereis mysql
[root@My-Server ~]#rpm -e --nodeps mysql-xxxx
[root@My-Server ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@My-Server ~]# rpm -e --nodeps mariadb-libs
警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave
[root@My-Server ~]# rpm -qa | grep mariadb
[root@My-Server local]# tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@My-Server local]# mv mysql-5.7.36-linux-glibc2.12-x86_64/ mysql
[root@My-Server local]# groupadd mysql
[root@My-Server local]# useradd -r -g mysql mysql
[root@My-Server local]# chown -R mysql:mysql mysql
[root@My-Server local]# chown -R 775 mysql
[root@My-Server local]# cd mysql/
[root@My-Server mysql]# mkdir data
[root@My-Server mysql]# cd bin/
[root@SQL-Server bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2022-07-23T02:08:48.796039Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-23T02:08:48.929499Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-23T02:08:48.967462Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-23T02:08:49.036866Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 63f7ae0d-0a2c-11ed-8598-000c298d2e7c.
2022-07-23T02:08:49.038071Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-23T02:08:49.295775Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-23T02:08:49.295805Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-23T02:08:49.296408Z 0 [Warning] CA certificate ca.pem is self signed.
记得记录后续登一次登录需要使用
2022-07-23T02:08:49.375844Z 1 [Note] A temporary password is generated for root@localhost: f:ege3PEwp5I
[root@My-Server bin]# vi /usr/local/mysql/support-files/mysql.server
[root@My-Server bin]# cd ../
[root@My-Server mysql]# cd ../
[root@My-Server local]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@My-Server local]# ll /etc/init.d/mysql
lrwxrwxrwx. 1 root root 43 7月 22 22:06 /etc/init.d/mysql -> /usr/local/mysql/support-files/mysql.server
[root@My-Server local]# vi /etc/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 作用是禁止域名解析:在mysql的授权表中就不能使用主机名了,只能使用IP
skip-name-resolve
# 设置3306端口
port = 3306
#设置远程访问ip
bind-address=0.0.0.0
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#设置查询操作等不区分大小写
lower_case_table_names=1
[root@My-Server local]# chmod -R 775 /etc/my.cnf
[root@Mysql-server support-files]# vim /etc/profile
文件最后添加内容
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/lib
[root@Mysql-server support-files]# source /etc/profile
[root@My-Server local]# service mysql start
[root@My-Server ~]# service mysql status
SUCCESS! MySQL running (4580)
[root@SQL-Server local]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36
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>
mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%'identified by '123456'
-> ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
select host,user,password_expired,password_last_changed,password_lifetime FROM mysql.user
drop user <用户名>
[root@My-Server local]# chkconfig --add mysql
[root@My-Server local]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@SQL-Server local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@SQL-Server local]# firewall-cmd --reload
success
[root@SQL-Server local]# firewall-cmd --list-ports
3306/tcp