环境搭建
# Centos 7安装MySQL5.7
# 准备工作
# 卸载MariaDB
[root@devstack ~]# rpm -qa | grep maria
mariadb-libs-5.5.68-1.el7.x86_64
[root@devstack ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
1
2
3
2
3
# 安装MySQL(yum方式)
# 配置MySQL yum源
也可以下载RPM直接安装。
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
1
2
2
# 安装MySQL服务
yum install -y mysql-community-server
1
# 安装MySQL(rpm方式)
# 下载MySQL安装包
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar
mkdir mysql
tar -xvf mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar -C mysql
1
2
3
2
3
# 安装MySQL
依次安装common
包、lib
包、client
包和server
包:
cd mysql
rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.38-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm
1
2
3
4
5
2
3
4
5
# 配置和启动MySQL
# 配置MySQL
修改配置,vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[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
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# mysql server port
port=3306
default_storage_engine=InnoDB
[client]
# client port
port=3306
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 启动MySQL服务
systemctl enable mysqld.service
systemctl start mysqld.service
1
2
2
# 配置密码和权限
查看初始密码:
grep "password" /var/log/mysqld.log
1登录MySQL
mysql -uroot -p
1配置密码
alter user 'root'@'localhost' indentified by '新密码'; # 本地登录
1配置远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '远程登录密码';; # 授权远程登录 flush privileges; exit;
1
2
3
# Windows安装MySQL5.7
这里用压缩包安装方式。
# 下载MySQL5.7安装
下载地址:https://dev.mysql.com/downloads/mysql/
下载Windows (x86, 64-bit), ZIP Archive
# 解压
下载完毕后将文件解压到你想保存到的盘和目录内。例如:D:\Program Files\MySQL57
# 配置环境变量
新建MYSQL_HOME环境变量,值为MySQL安装目录,并将变量MYSQL_HOME添加到环境变量Path。
新建环境变量:
添加到Path:
# 配置my.ini文件
在你的MySQL5.7安装目录下新建my.ini文件
[mysqld]
# 端口号
port = 3306
# MySQL5.7安装目录
basedir=D:\Program Files\MySQL57\mysql-5.7.37-winx64
# mysql数据存储路径
datadir=E:\Data\MySQL57\data
# 最大连接数
max_connections=200
# 编码
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log_timestamps=SYSTEM
log-error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 5
expire_logs_days = 15
secure-file-priv=E:\Data\MySQL57\Uploads
[mysql]
# 编码
default-character-set=utf85
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 安装MySQL
1、在输入框内输入cmd,以管理员的身份运行,注意这里一定一定一定要以管理员的身份运行,否则在安装过程中会出现因为管理权限不够而导致的Install/Remove of the Service Denied!(安装/卸载服务被拒绝),这一点非常重要!
2、在cmd下进去MySQL的安装目录的bin目录下
3、初始化数据库
mysqld --initialize-insecure
1
执行完毕之后,在data目录下会生成很多文件。
4、注册并启动MySQL服务
mysqld –install MySQL
1
install后面是服务的名字,我们这里以MySQL作为mysql5.7的服务名。
5、启动
net start mysql
1
# 登录并修改密码
提醒大家,由于初始化设置或版本差异,有些版本安装完成后root是空密码,有些是临时密码,我们需要查看error log日志提示。
日志路径在“mysql数据存储路径”的error.log,如E:\Data\MySQL57\data\error.log
。
下面我们命令行登录 修改下密码:
mysql -uroot -p
ALTER USER 'root'@'localhost' identified by 'mysql1234';
ALTER ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql1234' WITH GRANT OPTION;
flush privileges;
1
2
3
4
5
2
3
4
5
评论
上次更新: 2024/05/29, 14:25:22