Centos 7 下载安装 mysql server 5.7 (亲测可用)

Centos 7 下载安装 mysql server 5.7

 
更改权限
[zoro@localhost ~]$ su root
输入密码进来 管理者命令行

切换目录
[root@localhost zoro]# cd /root


下载安装包MySQL5.7 Linux版本
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

打开目录有这么个包
[root@localhost ~]# ls
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

安装依赖
[root@localhost ~]# rpm -qa |grep libaio
[root@localhost ~]#
[root@localhost ~]# yum -y install libaio
// 安装好后查看
[root@localhost ~]# rpm -qa |grep libaio
libaio-0.3.109-13.el7.x86_64

[root@localhost ~]# rpm -qa | grep numactl
[root@localhost ~]#
[root@localhost ~]# yum -y install numactl
//  安装好后查看
[root@localhost ~]# rpm -qa | grep numactl
numactl-libs-2.0.9-7.el7.x86_64

准备工作完毕!!!



解压准备好的安装包
[root@localhost ~]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

名字更改为mysql 并且修改位置
[root@localhost ~]# mv mysql-5.7.24-linux-glibc2.12-x86_64  /usr/local/mysql
[root@localhost ~]# cd /usr/local

创建mysql组,创建mysql用户,修改权限
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
//修改文件用户
[root@localhost local]# chown -R mysql mysql/
//修改文件用户组
[root@localhost local]# chgrp -R mysql mysql/
[root@localhost local]# ll
 

mysql 文件夹下创建data 目录
[root@localhost local]# mkdir /usr/local/mysql/data

编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)
 
cd /usr/local/mysql/bin


[root@localhost bin]#  ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US

 

2024-04-29T23:56:01.694886Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-04-29T23:56:02.130726Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-04-29T23:56:02.209312Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-04-29T23:56:02.285282Z 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: 08ae1c14-0684-11ef-bab1-5254007da070.
2024-04-29T23:56:02.292959Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-04-29T23:56:02.293617Z 1 [Note] A temporary password is generated for root@localhost: prrh2py  复制密码

 

mkdir -p /var/lib/mysql
chown mysql:mysql /var/lib/mysql


修改配置文件
[root@localhost local]# vi /etc/my.cnf

复制下面的, 贴到 /etc/my.cnf 里面

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端⼝
port = 3306
socket=/var/lib/mysql/mysql.sock
# 设置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
max_allowed_packet=16M

   
cd /usr/local/mysql


[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]#


复制启动脚本到资源⽬录
[root@localhost mysql]# vi /etc/init.d/mysqld

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

:wq
:wq 保存退出


设置为可执行状态

//授权为可执行状态
//⾸先增加 mysqld 服务控制脚本执⾏权限:
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
//开机启动
//同时将 mysqld 服务加⼊到系统服务:
[root@localhost mysql]# chkconfig --add mysqld
//最后检查 mysqld 服务是否已经⽣效即可:
[root@localhost mysql]# chkconfig --list mysqld



启动mysql

[root@localhost mysql]# service mysqld start
Starting MySQL.                                            [  确定  ]
Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-2-centos.err'.
2024-04-30T00:06:26.217074Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/VM-0-2-centos.pid).
  

配置环境变量
[root@localhost ~]# vi /etc/profile
//添加下面一行wq保存退出
export PATH=$PATH:/usr/local/mysql/bin
:wq
[root@localhost ~]#
//
[root@localhost ~]# source /etc/profile

 

登录mysql 密码是初始化中的最后localhost:后面的密码
(base) [root@VM-0-2-centos bin]# mysql
-bash: mysql: command not found


[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.24

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>
  

修改密码
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
 

开放远程连接
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>  update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>quit


==============================================================================================
但是还是有问题
windows 上的Navicat是连接不上的
这个问题该怎么解决呢?
打开远程访问权限,修改完退出mysql ,quit 命令

BY 后面是数据库密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>quit
Bye
  

防火墙开放mysql使用的3306端口
[root@localhost mysql]# cd /root
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
   

重启防火墙
[root@localhost ~]# systemctl restart firewalld.service
[root@localhost ~]#    

查看防火墙开放的端口
[root@localhost ~]# firewall-cmd --list-ports
3306/tcp
   

REF链接:

https://blog.csdn.net/Yeniden/article/details/136901092

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章