在CentOS系统上安装MySQL 5.5版本,可以通过多种方法实现,以下是详细的步骤和相关FAQs:
CentOS上通过YUM安装MySQL 5.5
1、更新系统并安装必要的工具
更新YUM包索引:
```bash
sudo yum update y
```
安装wget工具(如果尚未安装):
```bash
sudo yum install y wget
```
2、添加MySQL YUM仓库
下载MySQL YUM源:
```bash
wget HTTPS://dev.mysql.com/get/mysql55communityreleaseel69.noARCh.rpm
```
安装MySQL YUM源:
```bash
sudo rpm ivh mysql55communityreleaseel69.noarch.rpm
```
3、禁用其他MySQL版本并启用MySQL 5.5
查看所有可用的MySQL版本:
```bash
yum repolist all | grep mysql
```
禁用其他版本并启用MySQL 5.5:
```bash
sudo yumconfigmanager disable mysql80community
sudo yumconfigmanager enable mysql55community
```
4、安装MySQL 5.5
安装MySQL服务器及相关软件包:
```bash
sudo yum install y mysqlcommunityserver mysqlcommunityclient mysqlcommunitycommon mysqlcommunitylibs
```
5、启动MySQL服务并设置开机自启
启动MySQL服务:
```bash
sudo service mysqld start
```
设置MySQL服务开机自启:
```bash
sudo chkconfig mysqld on
```
6、初始化MySQL并修改root密码
查看临时密码:
```bash
grep 'temporary password' /var/log/mysqld.log
```
登录MySQL并修改密码:
```bash
mysql u root p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword!';
```
7、配置远程访问
授予远程访问权限:
```bash
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'NewPassword!' WITH GRANT OPTION;
FLUSH PRIVILEGES;
```
CentOS上通过二进制方式安装MySQL 5.5
1、准备安装环境
卸载残留的MariaDB:
```bash
rpm qa | grep mariadb
rpm e nodeps <mariadb_package>
```
删除配置文件:
```bash
rm /etc/my.cnf
```
2、下载安装包并解压
下载MySQL 5.5:
```bash
wget http://mirrors.sohu.com/mysql/MySQL5.5/mysql5.5.62linuxglibc2.12x86_64.tar.gz
```
解压文件:
```bash
tar zxvf mysql5.5.62linuxglibc2.12x86_64.tar.gz
```
3、移动并重命名文件夹
```bash
mv mysql5.5.62linuxglibc2.12x86_64 /usr/local/mysql5.5.60
cd /usr/local/mysql5.5.60
```
4、增加MySQL配置文件
```bash
vi /etc/my.cnf
# 内容参考如下:
[mysql]
defaultcharacterset=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skipnameresolve
port = 3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql5.5.60
datadir=/usr/local/mysql5.5.60/data
max_connections=200
charactersetserver=utf8
defaultstorageengine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
```
5、配置并安装数据库
```bash
groupadd mysql
useradd g mysql mysql
cd /usr/local/mysql5.5.60
chown R mysql:mysql ./
./scripts/mysql_install_db user=mysql basedir=/usr/local/mysql5.5.60/ datadir=/usr/local/mysql5.5.60/data/
```
6、启动MySQL服务并设置权限
```bash
cd /usr/local/mysql5.5.60
bin/mysqld_safe user=mysql &
bin/mysqladmin u root password 'newpassword'
```
相关FAQs
1、如何在CentOS上检查MySQL是否正在运行?:可以使用以下命令来检查MySQL服务的状态:service mysqld status
或者systemctl status mysqld
,如果服务正在运行,你会看到"active (running)"的状态信息,如果服务未运行,则会显示"inactive (dead)"或其他非运行状态的信息。
2、如何更改MySQL的默认字符集?:要更改MySQL的默认字符集,你需要编辑MySQL配置文件my.cnf
,在[mysqld]
部分添加或修改charactersetserver
选项,charactersetserver=utf8
,这将设置服务器的默认字符集为UTF8,保存文件后,重启MySQL服务以使更改生效:service mysqld restart
或systemctl restart mysqld
。