跳到主要内容

安装 mysql

Linux 上安装配置 mysql 数据库

离线安装 mysql

# 卸载原有的 mariadb
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs

# 下载安装包
# 根据操作系统和 glibc 的版本下载响应的安装包
ldd --version

tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar

逐个安装,命令如下:

# 【必须安装】
rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm

#【非必须安装】
rpm -ivh mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.16-2.el7.x86_64.rpm

导入数据库

-- 创建数据库
create database demo_db default character set utf8mb4 collate utf8mb4_unicode_ci;

-- 设置允许远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
UPDATE mysql.user SET host='%' WHERE user='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxx';

-- 导入数据库文件
mysql --user="root" --database="surveyking" --password="xx" < "/root/survey/reset-db/surveyking0728.sql"