Linux 安装Mysql

下载地址MySQL5.7.27参考

https://dev.mysql.com/downloads/file/?id=487589

安装MySQL5.7.27参考地址

https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html

下载安装
  1. 查看需要安装mysql的服务器版本并下载mysql安装包
[root@localhost ~]# cat /proc/version
Linux version 3.10.0-862.3.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Mon May 21 23:36:36 UTC 2018

这里我用的服务器是Red Hat的x86_64位的Linux,所以需要下载该Linux版本对应的mysql安装包

[root@localhost mysql]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
  1. 安装标准的mysql
[root@localhost mysql]# tar -xvf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-5.7.27-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.27-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm
mysql-community-devel-5.7.27-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.27-1.el7.x86_64.rpm
mysql-community-common-5.7.27-1.el7.x86_64.rpm
mysql-community-client-5.7.27-1.el7.x86_64.rpm
mysql-community-server-5.7.27-1.el7.x86_64.rpm
mysql-community-test-5.7.27-1.el7.x86_64.rpm
mysql-community-embedded-5.7.27-1.el7.x86_64.rpm
[root@localhost mysql]#  sudo yum install mysql-community-{server,client,common,libs}-*

安装成功可以看到

Installed:
  mysql-community-client.x86_64 0:5.7.27-1.el7                                          
  mysql-community-common.x86_64 0:5.7.27-1.el7                                          
  mysql-community-libs.x86_64 0:5.7.27-1.el7                                            
  mysql-community-libs-compat.x86_64 0:5.7.27-1.el7                                     
  mysql-community-server.x86_64 0:5.7.27-1.el7                                          

Complete!
  1. 启动mysql
[root@localhost mysql]# sudo service mysqld start
  1. 设置超级用户密码
    4.1 关掉mysql
[root@localhost mysql]# sudo service mysqld stop

4.2 修改/etc/my.cnf,打开my.cnf文件,在mysqld下面添加skip-grant-tables,保存退出。

[root@localhost mysql]# vim /etc/my.cnf
# innodb_buffer_pool_size = 128M
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
skip-grant-tables
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

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

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

4.3 启动mysql

[root@localhost mysql]# sudo service mysqld start

4.4 进入mysql数据库,修改root密码为Frank@668

[root@localhost mysql]# mysql -u root -p
Enter password: #直接点击确认
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 mysql.user set authentication_string=password('Frank@668') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1

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

mysql> quit;
Bye

4.5 修改/etc/my.cnf ,删掉skip-grant-tables,重新启动mysql

[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# sudo service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

4.6 重新使用root账号进入mysql,使用ALTER 重置密码

[root@localhost mysql]# mysql -u root -p
Enter password: #输入刚刚设置的密码Frank@668
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Frank@668';
Query OK, 0 rows affected (0.00 sec)
  1. 远程链接
    5.1 赋予root权限
[root@localhost mysql]# mysql -u root -p
Enter password: #输入刚刚设置的密码Frank@668
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
mysql> grant all privileges on *.*  to  'root'@'%'  identified by 'Frank@668'  with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

5.2 开启3306端口

[root@localhost mysql]# systemctl start firewalld
[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost mysql]# firewall-cmd --reload

5.3 远程链接
image.png

开源一个微信公众号留言小程序,欢迎大家Fork:
https://github.com/fuxingkai/LMsg

### 安装 MySQL 的准备工作 在Linux系统上安装MySQL前,需确认当前环境中是否已存在旧版MySQL实例。这一步骤至关重要,因为残留的MySQL组件可能会引发冲突。可以利用`rpm -qa | grep mysql`来检测现有安装情况[^1]。 ### 获取并准备 MySQL 软件包 对于基于RPM的发行版,如CentOS或Red Hat Enterprise Linux (RHEL),可以通过wget命令下载官方提供的MySQL软件包。例如: ```bash wget http://dev.mysql.com/get/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar ``` 此操作会获取适用于特定版本Linux系统的MySQL压缩文件[^2]。 ### 解压与部署 MySQL 文件夹 下载完成后,使用tar工具解压所获得的`.tar.gz`格式档案至指定位置,通常建议放置于`/usr/local/`路径下作为标准实践的一部分: ```bash tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql ``` 上述指令实现了将解压后的MySQL目录复制到目标位置的操作[^3]。 ### 创建专用用户和服务脚本设置 为了安全性和权限管理的目的,应当创建专门用于运行MySQL进程的新用户和组。此外,还需把MySQL的服务控制脚本拷贝到初始化脚本的位置,并赋予其可执行权限以及注册为开机自启项之一: ```bash cp -a ./support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql chkconfig --add mysql ``` 这些步骤确保了MySQL能够被正确识别为操作系统级别的服务[^4]。 ### 启动 MySQL 服务 完成以上配置之后,即可尝试启动MySQL服务以验证整个安装过程的成功与否: ```bash service mysql start ``` 如果一切顺利,则表示MySQL已经在Linux平台上成功安装完毕。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值