CentOS 7.x 系统linux-glibc-tar.gz包方式安装mysql 5.7.36

【下载安装包】

官网下载地址:https://dev.mysql.com/downloads/file/?id=507442
 
安装包:mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
 
 https://dev.mysql.com/downloads/file/?id=507442

【查询卸载旧版本】

# 查看启动状态,如果是运行中则需要先停止mysql服务
# service mysqld status
# ps -e |grep mysqld

# rpm -aq|grep mysql
# find / -name mysql
# whereis mysql

# rm -rf "所有查询到的安装残留"

# yum remove mysql mysql-server mysql-libs mysql-server -y

【下载+解压缩+重命名安装目录】

# j解压
# tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

# 改名文件夹:mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
# 此时就是mysql的默认安装路径:/usr/local/mysql,建议不要更换,否则要你自己更新配置  


【添加用户与用户组】

# groupadd mysql 
# useradd -s /sbin/nologin -M -g mysql mysql

说明:
-s:表示指定用户所用的shell,此处为/sbin/nologin,表示不登录。
-M:表示不创建用户主目录。
-g:表示指定用户的组名为mysql
   
# 授权mysql用户权限
# chown -R mysql:mysql /usr/local/mysql

【初始化前创建mysql数据文件夹】

# mkdir -p /var/lib/mysql/data   -- 要与后面的my.cnf配置文件中保持一直

【初始化mysql】

# cd /usr/local/mysql/bin

# ./mysqld --initialize --user=mysql   -- 如果需要重新初始化,则必须删除data目录下的所有内容,再重新执行此命令

[root@VM-16-2-centos bin]# ./mysqld --initialize --user=mysql
2021-11-06T14:46:36.862864Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-06T14:46:37.140217Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-06T14:46:37.192305Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-06T14:46:37.256308Z 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: 5826202c-3f10-11ec-839f-525400f5b14c.
2021-11-06T14:46:37.259405Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-06T14:46:38.367560Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-11-06T14:46:38.367579Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-11-06T14:46:38.368252Z 0 [Warning] CA certificate ca.pem is self signed.
2021-11-06T14:46:38.481882Z 1 [Note] A temporary password is generated for root@localhost: Pq7q8rakYR)X

【配置mysql服务与文件】

# cd ../support-files/

# cp support-files/mysql.server /etc/init.d/mysqld

# 完整路径复制:cp /opt/soft/mysql/mysql-5.7.36/support-files/mysql.server /etc/init.d/mysqld

【配置mysql配置文件:my.cnf】
# vim /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/data/mysql.sock
character-set-server=utf8
port=3306

[client]
socket=/var/lib/mysql/data/mysql.sock
default-character-set=utf8
port=3306

# Disabling symbolic-links is recommended to prevent assorted security risks

# 建议禁用符号链接以防止各种安全风险
# symbolic-links=0

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysql]
default-character-set=utf8
port=3306

#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid

【配置环境变量】

# vim /etc/profile

export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

# source /etc/profile


【配置开机启动】

# systemctl enable mysqld

[root@VM-16-2-centos local]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on

【启动mysql服务】

# systemctl start mysqld   -- 5.7.36 版本启动如果报错,可能需要创建文件夹: mkdir -p /etc/my.cnf.d/
# systemctl status mysqld
# systemctl stop mysqld

# 查看服务启动情况
# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since 六 2021-11-06 22:36:32 CST; 20s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 17013 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mysqld.service
           ├─17024 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/VM-16-2-centos.pid
           └─17178 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/pl...

11月 06 22:36:31 VM-16-2-centos systemd[1]: Starting LSB: start and stop MySQL...
11月 06 22:36:31 VM-16-2-centos mysqld[17013]: Starting MySQL.Logging to '/var/lib/mysql/VM-16-2-centos.err'.
11月 06 22:36:32 VM-16-2-centos mysqld[17013]: SUCCESS!
11月 06 22:36:32 VM-16-2-centos systemd[1]: Started LSB: start and stop MySQL.


【重置密码】

# mysql -u root -p
Enter password:    -- 这里输入上面初始化生成的密码:"Pq7q8rakYR)X"

alter user 'root'@'localhost' identified by 'root123';

[root@VM-16-2-centos bin]# 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> alter user 'root'@'localhost' identified by 'root123';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

【授权远程访问】

# mysql -u root -p   -- 使用新密码登录

# grant all privileges on *.* to 'root'@'%' identified by 'root123' with grant option;

# 设置密码永不过期
# alter user 'root'@'%' password expire never;
# flush privileges;

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root123' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit;
Bye

【防火墙开放端口】

# 查询已开放的端口:netstat  -ntulp | grep 3306
# 查询指定端口是否已开放:firewall-cmd --query-port=3306/tcp

# 查看防火墙状态:systemctl status firewalld
# 开启防火墙:systemctl start firewalld  
# 关闭防火墙:systemctl stop firewalld
# 开启防火墙:service firewalld start 

# 开放端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 加载配置:firewall-cmd --reload

【远程客户端连接测试 - 略...】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值