Centos 7安装MySQL5.6

发布时间 2023-04-27 09:31:29作者: 成佛在西天

安装步骤

  确保之前未安装;若存在则要卸载

// 查看主机是否已经安装了mysql(如果存在则要卸载)
rpm -qa|grep mysql
// 卸载命令
rpm -e --nodeps "上面检索出的mysql安装包"

  下载mysql的yum源

wget -P /usr/software http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
// 验证是否下载成功
ll /usr/software/

  安装下载好的yum源

cd /usr/software/
rpm -ivh mysql-community-release-el6-5.noarch.rpm
ll /etc/yum.repos.d

  使用yum安装MySQL服务器

yum search mysql
yum install -y mysql-community-server

  启动MySQL服务并查看状态

service mysqld start
service mysqld status

  修改MySQL密码

// mysql5.6 安装完成后,它的 root 用户的密码默认是空的,我们需要及时用 mysql 的 root 用户登录(第一次直接回车,不用输入密码),并修改密码。
mysql -u root

mysql> use mysql;
mysql> update user set password=PASSWORD("这里输入root用户密码") where User='root';
mysql> flush privileges;

 

遇到的问题

  查看mysql服务器状态,发现是正常启动的,但就是无法连接MySQL,报如下错误

Can't connect to local MySQL server through socket '/tmp/mysql.sock'

  解决方法就是在/etc/my.cnf里面添加一个[client]

// 要保证[mysqld]和[client]终端socket路径一样
[mysqld]
#
# 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

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

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


[client]
socket = /var/lib/mysql/mysql.sock

参考链接

[1]https://www.cnblogs.com/gscq073240/articles/16730724.html

[2]https://blog.csdn.net/pengjunlee/article/details/81212250

[3]https://blog.csdn.net/qq_42347255/article/details/113700167

[4]https://www.jb51.net/article/174244.htm