1.将安装包上传到linux服务器
? ?可以使用rz命令进行 上传
? ?创建app目录用来存放mysql
2.解压安装包?
[root@localhost app]# tar xvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
由于解压之后名字 太长,这里笔者对 mysql目录进行了修改 ,修改成为了mysql
3.配置环境变量?
? ?在/etc/profile文件的末尾追加
export PATH=/app/mysql/bin:$PATH
?执行source命令
[root@localhost bin]# source /etc/profile
4.创建数据目录?
[root@localhost ~]# mkdir data/mysql -p
5.创建用户并授权
[root@localhost ~]# chown -R mysql.mysql /app/*
[root@localhost ~]# chown -R mysql.mysql /data/*
6.数据库初始化
? 第一种初始化方式
[root@localhost ~]# mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data/mysql
可能会报如下错误
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
原因:操作系统中缺少libaio-devel包
解决 :
[root@localhost ~]# yum install -y libaio-devel
再重新执行数据库初始化命令
[root@localhost ~]# mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2021-10-26T20:58:58.040542Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T20:58:58.765886Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T20:59:00.026036Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T20:59:00.274919Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8b14f390-369f-11ec-9c86-000c29df45df.
2021-10-26T20:59:00.286261Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T20:59:01.111451Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T20:59:01.315125Z 1 [Note] A temporary password is generated for root@localhost: ?Qh4gk3!_UwX
注意:1.初始化完成后在末尾会有初始密码
? ? ? ? ? ?2.自己设置的密码复杂度要高,12位及以上;
? ? ? ? ? ?3.密码过期时间是180天
如果不想要上面的注意事项生效,数据库初始化命令可以使用如下方式:
第二种初始化方式
[root@localhost ~]# mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql
推荐使用第二种
7.编辑配置文件
如果使用的是第二种,可以通过如下命令添加编辑配置文件
[root@localhost ~]# vim /etc/my.cnf
最简单的文件内容如下
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
8.启动和关闭mysql
? ?方式1
? ? ? 启动
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cd /app/mysql/support-files/
[root@localhost support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
. SUCCESS!
? ? ?关闭
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cd /app/mysql/support-files/
[root@localhost support-files]# ./mysql.server stop
Shutting down MySQL.. SUCCESS!
方式2
拷贝mysql.server文件到/etc/init.d/mysqld下
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
启动、重启、关闭、查询运行状态命令如下
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS!
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost ~]# service mysqld status
方式 3:
?使用systemd管理mysql
vim /etc/systemd/system/mysqld.service
添加如下内容
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
启动、重启、关闭、查询运行状态命令如下
systemctl start mysqld
systemctl restart mysqld
systemctl stop mysqld
systemctl status mysqld
注意:配置文件的具体配置,在后续更新
|