Centos 7安装MySQL5.6
安装步骤
确保之前未安装;若存在则要卸载
// 查看主机是否已经安装了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>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~