赞
踩
一直使用的都是MariaDB,突然想使用以下mysql,虽然二者基本差别不大,但还是记录一下吧。
Linux系统版本:CentOS_7.5
这里虽然mysql有8.0版本,但是不太稳定,我还是喜欢使用5.7版本,二者在安装是基本没有差别的,那这里就是用5.7版本为例吧。
我们下载的是免编译二进制安装包,我们都知道采用源码包安装mysql还需要编译,编译过程所花费的时间是极其漫长的,因此,我们就采用免编译二进制包安装即可,下载包之后,解压之后,不用编译,直接初始化就能使用了。
这里使用清华源镜像(下载速度比较快),当然也可以使用mysql官网中的包。
清华源镜像地址:https://mirrors.tuna.tsinghua.edu.cn/mysql/
进入网站有三个大分类,下面来介绍一下:
因为我们需要安装二进制包,因此我们选用"downloads"。
1、先查看自己的系统是多少位的
[root@node3 ~]# uname -i
x86_64
2、下载对应64位的免编译二进制包
[root@node3 ~]# yum install -y wget
[root@node3 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz --no-check-certificate #有的不需要"--no-check-certificate",表示不用证书检查。
1、基础操作
[root@node3 ~]# tar -xzvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz [root@node3 ~]# mv mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql [root@node3 ~]# useradd -s /sbin/nologin mysql #创建mysql用户,因为启动mysql需要该用户 [root@node3 ~]# mkdir -p /data/mysql #创建datadir,数据库文件会放在这里 [root@node3 ~]# chown -R mysql:mysql /data/mysql/ #更改权限,此文件需要使用mysql用户进行操作,要不然操作会报错 [root@node3 etc]# vi my.cnf [mysqld] datadir=/data/mysql #存放数据库文件的目录 socket=/tmp/mysql.sock #mysql的套接字文件路径,套接字用于mysql进程之间通信,用于mysql Server和mysql Client之间通信。 innodb_buffer_pool_size=128M #缓存池大小 port=3306 #定义mysql端口,如果不写,默认也是3306 basedir=/usr/local/mysql/ #存档mysql程序的目录 pid_file = /data/mysql/mysql.pid # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
2、创建pid,log文件,并授权
以下操作对应的是/etc/my.cnf文件中的[mysqld_safe]部分
[root@node3 ~]# mkdir /var/log/mariadb/
[root@node3 ~]# touch /var/log/mariadb/mariadb.log
[root@node3 ~]# mkdir /var/run/mariadb/
[root@node3 ~]# touch /var/run/mariadb/mariadb.pid
[root@node3 ~]# chown -R mysql:mysql /var/log/mariadb/
[root@node3 ~]# chown -R mysql:mysql /var/run/mariadb/
3、初始化mysql
yum install -y libaio #安装初始化mysql所依赖的包
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
#初始化mysql,初始化成功会在/data/mysql下面生成一大堆目录和文件,该命令执行成功后会有一个临时密码,用于登陆mysql
2022-04-23T11:41:08.217341Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-04-23T11:41:08.563371Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-04-23T11:41:08.631758Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-23T11:41:08.706278Z 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: 446a260e-c2fa-11ec-859a-000c29d6ee76.
2022-04-23T11:41:08.707704Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-04-23T11:41:09.399711Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-04-23T11:41:09.399738Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-04-23T11:41:09.401410Z 0 [Warning] CA certificate ca.pem is self signed.
2022-04-23T11:41:09.629326Z 1 [Note] A temporary password is generated for root@localhost: 2>6.lj(t>i9J
#A temporary password is generated for root@localhost: 2>6.lj(t>i9J ,其中"2>6.lj(t>i9J"就是临时密码。
补充:如果发现初始化写错了咋办?直接删除数据库的数据即可
rm -rf /data/mysql/*
3、启动mysql服务
vi .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin #将/usr/loca/mysql/bin添加上
#刷新变量
source .bash_profile
#复制启动项
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#添加启动项
chkconfig --add mysqld
#开启mysql服务
systemctl restart mysqld
#查看端口3306
[root@node3 ~]# ss -ntpul
...
tcp LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=19215,fd=20))
...
4、设置新密码,并登录进mysql
[root@node3 ~]# mysqladmin -uroot -p:8ey*d%TQ,lC password '123456' #设置新密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure. #警告信息不用管
5、登陆mysql
[root@node3 ~]# mysql -uroot -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.35 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> #可以看到成功登陆 mysql> create database bo; #创建个数据库 Query OK, 1 row affected (0.00 sec)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。