MySql教程

MySQL单机安装

本文主要是介绍MySQL单机安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

以下安装环境为Red Hat Enterprise Linux Server release 7.4 (Maipo)

Server version: 5.7.28

1.创建data soft log磁盘

fdisk /dev/sdb //磁盘分区
pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3 //创建物理卷
vgcreate vg_soft /dev/sdb1 /dev/sdb2 /dev/sdb3 //创建卷组
lvcreate -L29.98G -n lv_soft vg_soft //创建逻辑卷
fdisk /dev/sdc
pvcreate /dev/sdc1 /dev/sdc2 /dev/sdc3 /dev/sdc5 /dev/sdc6
vgcreate vg_log /dev/sdc1 /dev/sdc2 /dev/sdc3 /dev/sdc5 /dev/sdc6
lvcreate -L 49.98G -n lv_log vg_log
//创建挂载点
mkdir /data
mkdir /log
mkdir /soft

fdisk /dev/sdd
pvcreate /dev/sdd1 /dev/sdd2 /dev/sdd3 /dev/sdd5 /dev/sdd6
vgcreate vg_data /dev/sdd1 /dev/sdd2 /dev/sdd3 /dev/sdd5 /dev/sdd6
lvcreate -L 99.98G -n lv_data vg_data
//格式化
mkfs.ext4 /dev/vg_log/lv_log
mkfs.ext4 /dev/vg_soft/lv_soft
mkfs.ext4 /dev/vg_data/lv_data
//写入文件中,重启后自动mount
vim /etc/fstab
/dev/vg_data/lv_data /data ext4 defaults 0 0
/dev/vg_soft/lv_soft /soft ext4 defaults 0 0
/dev/vg_log/lv_log /log ext4 defaults 0 0

2.上传文件并解压

tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
修改文件名
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
修改环境变量

修改完成后source下生效
source .bash_profile
修改完成mysqld -V能打印出MySQL版本即为成功

3.创建相关目录,以及赋予目录mysql属组,创建mysql用户

** 可根据自己的环境情况创建相关目录,此处创建的目录为/data/conf/data3306,/data/conf/data3307,/data/conf/data3308,/data/conf/data3309 目的为以后的同版本多实例安装准备**

[root@localhost ~]# useradd mysql
[root@localhost ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
[root@localhost ~]# mkdir -p /data/conf/330{6..9} //配置文件目录
[root@localhost ~]# mkdir -p /log/330{6..9}
[root@localhost ~]# mkdir -p /data/330{6..9}/data //数据目录
[root@localhost ~]# chown -R mysql.mysql /data
[root@localhost ~]# chown -R mysql.mysql /log
[root@localhost ~]# chown -R mysql.mysql /soft

4.初始化实例

mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/3306/data
初始化过程无ERROR即为正常,WARNING可忽略,该命令可初始化该实例的root为空密码

该命令可生成一个临时密码
具体操作步骤为:

[root@localhost 3306]# cd data/
[root@localhost data]# ls
auto.cnf client-cert.pem ibdata1 mysql public_key.pem sys
ca-key.pem client-key.pem ib_logfile0 performance_schema server-cert.pem
ca.pem ib_buffer_pool ib_logfile1 private_key.pem server-key.pem
[root@localhost data]# rm -rf *
[root@localhost data]# mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2022-02-11T21:46:34.067098Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use -- explicit_defaults_for_timestamp server option (see documentation for more details).
2022-02-11T21:46:34.067191Z 0 [ERROR] Can't find error-message file '/app/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2022-02-11T21:46:34.179285Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-02-11T21:46:34.200482Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-02-11T21:46:34.266624Z 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: 14ce86df-8b84-11ec-83d7-000c29245cff.
2022-02-11T21:46:34.270449Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-02-11T21:46:34.970691Z 0 [Warning] CA certificate ca.pem is self signed.
2022-02-11T21:46:35.216739Z 1 [Note] A temporary password is generated for root@localhost: tefXI7zzD2-W

以上为5.7初始化方法
5.6初始化的命令为:

/application/mysql/scripts/mysql_install_db --user=mysql --datadir=/application/mysql/data -- basedir=/application/mysql

5.编辑一个临时的配置文件

[mysqld]
user=mysql
basedir=/soft/mysql
datadir=/data/3306/data
log_error=/log/3306/error.log
log_bin=/log/3306/mysql-bin
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\d]>

6.配置启动脚本

[root@localhost support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@localhost support-files]# pwd
/soft/mysql/support-files
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld

7.启动MySQL实例

[root@localhost support-files]# service mysqld start
Starting MySQL.2022-02-11T21:54:54.419230Z mysqld_safe error: log-error set to '/log/3306/error.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/data/3306/data/localhost.localdomain.pid).

启动实例报错,根据报错信息可知该文件不存在,或者权限不对

[root@localhost 3306]# touch error.log
[root@localhost 3306]# ls
error.log
[root@localhost 3306]# chown mysql.mysql error.log
[root@localhost 3306]# ll
total 0
-rw-r--r--. 1 mysql mysql 0 Feb 11 16:56 error.log

修改完成后启动成功
[root@localhost data]# service mysqld start
Starting MySQL. SUCCESS!

8.启动后可正常连接

安装过程中,初始化时注意填写正确的data目录,否则可能启动时报错如下,以下报错是我自行安装时,初始化写错路径的报错

这篇关于MySQL单机安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!