Centos7 安装 mysql
下载mysql安装包
mysql官网地址: mysql官网
安装前执行操作
- rpm -qa | grep mariadb 判断是否已经安装mariadb 防止与mysql发生冲突
- rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps 卸载mariadb
- 再查看是否卸载完成
安装步骤
- 上传文件到/usr/local/下
- 新建文件夹 mkdir mysql
- cd /usr/local/mysql
- tar -xvf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
- rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm --nodeps --force
- rpm -ivh mysql-community-libs-5.7.32-1.el7.x86_64.rpm --nodeps --force
- rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm --nodeps --force
- rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm --nodeps --force
- rpm -qa | grep mysql
- mysqld --initialize;
- chown mysql:mysql /var/lib/mysql -R;
- systemctl start mysqld.service;
- systemctl enable mysqld;
- cat /var/log/mysqld.log | grep password 查看密码
- mysql -uroot -ppassword
- exit
glibc方式安装
- 1、下载压缩包
- 2、复制/usr/local/mysql下并解压
- 3、创建data目录 mkdir /usr/local/mysql/data
- 4、创建my.cnf vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
# 跳过密码验证
skip-grant-tables=1
- 5、初始化mysql 在/usr/local/mysql目录下
bin/mysqld --initialize --user=mysql --basedir=/usr/loacl/mysql
- 6、添加MySQL全局环境变量
# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile
- 7、启动mysql
service mysql start
- 8、修改数据库密码和配置远程登录
# 选择数据库
use mysql;
# 修改密码
update mysql.user set authentication_string=password('新密码') where user='root' and Host='localhost';
# 修改生效
flush privileges;
# 配置远程登录
update user set host = '%' where user = 'root';
遇坑
- 执行mysqld --initialize;缺少libaio.so.1
答:安装libaio.so.1
yum search libaio
选择对应版本安装 64位选择libaio-devel.x86_64安装即可