centos 7下mysql5.7的配置安装

本文提供了一步一步的指导来帮助读者在Linux环境下安装MySQL数据库。包括下载安装包、配置环境、安装初始化、设置权限及远程访问等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载安装包地址:https://dev.mysql.com/downloads/mysql/

如图:

检查是否已安装mysql
  [root@izwz93zazliojetgsr3tymz ~]# yum list installed | grep mysql 或rpm -qa | grep mysql
移除已安装包
  yum -y remove + 需移除包名
检查mysql组和用户是否存在,如无创建
[root@izwz93zazliojetgsr3tymz ~]# cat /etc/group | grep mysql 
[root@izwz93zazliojetgsr3tymz ~]#  cat /etc/passwd | grep mysql
创建mysql用户组
[root@izwz93zazliojetgsr3tymz ~]# groupadd mysql
创建一个用户名为mysql的用户并加入mysql用户组
[root@izwz93zazliojetgsr3tymz ~]# useradd -g mysql mysql
制定密码为123456
[root@izwz93zazliojetgsr3tymz ~]# passwd mysql
Changing password for user mysql.
New password: (注意:输入密码时是不可见的!)
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
安装到/usr/local (将下载好的安装包移进此目录下,解压)
[root@izwz93zazliojetgsr3tymz local]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 
重命名
[root@izwz93zazliojetgsr3tymz local]# mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql57
(如果安装包不需要可执行删除[root@izwz93zazliojetgsr3tymz local]# rm -rf mysql-5.7.18-linux-   
   glibc2.5-x86_64.tar.gz )
更改所属的组和用户
[root@izwz93zazliojetgsr3tymz local]# chown -R mysql mysql57/
[root@izwz93zazliojetgsr3tymz local]# chgrp -R mysql mysql57/
[root@izwz93zazliojetgsr3tymz local]# cd mysql57/
[root@izwz93zazliojetgsr3tymz mysql57]# mkdir data
[root@izwz93zazliojetgsr3tymz mysql57]# chown -R mysql:mysql data
查找是否有my.cnf文件如果没有则看下一步(有则直接看下面my.cnf的配置)
[root@izwz93zazliojetgsr3tymz /]# find / -iname '*.cnf' -print
/root/node-v9.0.0/test/fixtures/openssl_fips_disabled.cnf
/root/node-v9.0.0/test/fixtures/openssl_fips_enabled.cnf
/root/node-v9.0.0/test/fixtures/keys/fake-cnnic-root.cnf
/root/node-v9.0.0/test/fixtures/keys/agent2.cnf
/root/node-v9.0.0/test/fixtures/keys/agent1.cnf
/root/node-v9.0.0/test/fixtures/keys/ca3.cnf
/root/node-v9.0.0/test/fixtures/keys/ca1.cnf
/root/node-v9.0.0/test/fixtures/keys/agent4.cnf
/root/node-v9.0.0/test/fixtures/keys/ca2.cnf
没有则复制一个到/etc下
[root@izwz93zazliojetgsr3tymz /]# cp /root/node-v9.0.0/test/fixtures/keys/ca3.cnf /etc
[root@izwz93zazliojetgsr3tymz /]# cd /etc
更改文件名
[root@izwz93zazliojetgsr3tymz /]# mv ca3.cnf my.cnf
在etc下my.cnf文件内添加以下配置
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
skip-name-resolve
# 设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=/usr/local/mysql57
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql57/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
lower_case_table_names=1
max_allowed_packet=16M
安装与初始化
[root@izwz93zazliojetgsr3tymz /]# cd /usr/local/mysql57
[root@izwz93zazliojetgsr3tymz mysql57]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql57/ --datadir=/usr/local/mysql57/data/
2017-11-29 15:19:39 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-11-29 15:19:48 [WARNING] The bootstrap log isn't empty:
2017-11-29 15:19:48 [WARNING] 2017-11-29T07:19:40.928235Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

[root@izwz93zazliojetgsr3tymz mysql57]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@izwz93zazliojetgsr3tymz mysql57]# chown 777 /etc/my.cnf 
[root@izwz93zazliojetgsr3tymz mysql57]# chmod +x /etc/init.d/mysqld

[root@izwz93zazliojetgsr3tymz mysql57]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
设置开机启动
[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --level 35 mysqld on
[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --list mysqld

[root@izwz93zazliojetgsr3tymz mysql57]# chmod +x /etc/rc.d/init.d/mysqld
[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --add mysqld
[root@izwz93zazliojetgsr3tymz mysql57]# chkconfig --list mysqld
[root@izwz93zazliojetgsr3tymz mysql57]# service mysqld status
 SUCCESS! MySQL running (20157)
修改/etc/profile文件
[root@izwz93zazliojetgsr3tymz mysql57]# vi /etc/profile
在profile中增加此句:export PATH=$PATH:/usr/local/mysql57/bin
让其生效:
[root@izwz93zazliojetgsr3tymz mysql57]# source /etc/profile
(此过程出现不识别指令错误退出重新进入即可!)
获得初始密码
[root@izwz93zazliojetgsr3tymz mysql57]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-11-29 15:19:39 
Pi%hFtk0*rhI
修改密码
[root@izwz93zaz1iojetgsr3tymz /]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20

Copyright (c) 2000, 2017, 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> set PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 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 host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+
2 rows in set (0.00 sec)

# create user 'xxx'@'%' identified by '123';  这里 @‘%’ 表示在任何主机都可以登录
mysql> quit;退出重启
[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart 
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
查看字符集
mysql> show variables like 'character%';

如图:

到此完结!

注意:如果是安装在阿里云服务器上,那么需要添加安全组然后进行远程连接

这里写图片描述

END!!!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值