目录
1、下载安装包
# 创建安装目录
[root@pdyb ~]# mkdir -p /soft/
# cd 进入到安装目录
[root@pdyb ~]# cd /soft/
# 通过wget命令直接下载到目录
注意:电脑需要联网,需要配置yum源
#通过yum安装wget命令
[root@pdyb soft]# yum -y install wget
# 下载mysql安装包
[root@pdyb soft]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar
不能上网,可以去官网下载,通过ftp上传到电脑,官网下载地址:
MySQL :: Download MySQL Community Server (Archived Versions)
https://downloads.mysql.com/archives/community/

2、创建目录、解压
#创建解压目录
mkdir -p /u02/local/
# 解压
[root@pdyb soft]# tar -xvf mysql-5.7.36-linux-glibc2.12-x86_64.tar
mysql-test-5.7.36-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@pdyb soft]# tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /u02/local/mysql[root@pdyb soft]# tar -zxvf mysql-test-5.7.36-linux-glibc2.12-x86_64.tar.gzC [root@pdyb [root@pdyb soft]# cd /u02/local/
[root@pdyb local]# mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
3、创建组、用户、数据目录并授权
groupadd mysql
useradd -g mysql mysql
mkdir -p /u02/local/mysql/data
chown -R mysql:mysql /u02/
4、MySQL初始化
将my.cnf文件复制到/etc/,mysql配置文件如下,可以通过vi my.cnf手动创建文件(这里使用我们的配置文件)
vi my.cnf
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/u02/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/u02/local/mysql/data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
# mysql_native_password
default_authentication_plugin=mysql_native_password
explicit_defaults_for_timestamp=true
# 日志文件目录
log-error=/u02/local/mysql/data/mysql.error
# pid文件目录:记录当前mysql进程的pid
pid-file=/u02/local/mysql/data/mysql.pid
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
# 进入mysql 目录
# 开始初始化
./bin/mysqld --defaults-file=/etc/my.cnf --basedir=/u02/local/mysql --datadir=/u02/local/mysql/data --user=mysql --initialize

注意:需要记住红框标注的密码。
5、修改默认密码并设置
# 进入mysql目录
cd /u02/local/mysql/
# 开启mysql服务
[root@pdyb mysql]# ./support-files/mysql.server start
./bin/mysql -u root -p

#修改密码
mysql> set password for root@localhost=password('123456');
#刷新配置
flush privileges;
# 访问mysql库
use mysql
# 修改root用户能在任何host访问(授权远程连接)
update user set host = '%' where user = 'root';
# 刷新配置
flush privileges;

6、设置开机自启
# 设置软连接
ln -s /u02/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /u02/local/mysql/bin/mysql /usr/bin/mysql
# 打开、关闭数据库
service mysql restart
service mysql start
service mysql stop
#赋予权限
chmod +x /etc/init.d/mysql
#添加服务
chkconfig --add mysql
#显示服务列表
chkconfig --list
注意:如果2345不是开状态,执行以下语句:
chkconfig --level 2345 mysql on



1014

被折叠的 条评论
为什么被折叠?



