1. 下载安装包
=======================================================
2. 卸载主机自带的mysql或mariadb
执行下边的命令:
rpm -qa|grep mysql
rpm -qa|grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@localhost ~]#root@liandoyun ~]# rpm -e –nodeps mariadb-libs-5.5.64-1.el7.x86_64
=======================================================
3. 安装mysql
[root@localhost ~]# mkdir /softbak (创建一个文件夹,用来放我们的Mysql)
上传安装包至/softbak (我相信你们可以做到)
[root@localhost~]# cd /softbak/ (移动到softbak文件夹)
[root@localhostsoftbak]# ls (查看文件夹中的内容)
mysql-8.0.20-el7-x86_64.tar.gz (可以看到,安装包已经移过来了)
接下来,将压缩包解压到/usr/local/
[root@localhost softbak]# tar -xzvf mysql-8.0.20-el7-x86_64.tar.gz -C /usr/local/
[root@localhost softbak]# cd /usr/local/ (移动到local目录下)
[root@localhost local]# ls (查看目录下的文件)
(下边这行不是命令,是我们打开的目录下的文件,可以看到我们的Mysql已经解压过来了)
bin etc games include lib lib64 libexec mysql-8.0.20-el7-x86_64 sbin share src
[root@localhost local]# mv mysql-8.0.20-el7-x86_64/ mysql/ (移动到Mysql目录中)
=======================================================
4.创建mysql用户和组(如果提示已存在也正常,继续往下操作就好了)
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql
=======================================================
5.创建目录并授权
[root@localhost mysql]# mkdir /var/lib/mysql
[root@localhost mysql]# mkdir /usr/local/mysql/log
[root@localhost mysql]# mkdir /usr/local/mysql/data
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql
[root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql
=======================================================
6.添加环境变量
[root@localhost mysql]# vim ~/.bash_profile (打开文件进行编辑)
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin (需要修改的内容)
[root@localhost ~]# source ~/.bash_profile (执行命令,让我们的修改立即生效)
=======================================================
7.配置参数文件
[root@localhost mysql]# vim /etc/my.cnf (编辑my.cnf,将下边的文本全部粘贴进来,记得是“全部”粘贴不全后边的操作必报错)
[mysql]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
[mysqld]
port = 3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
character-set-server=utf8mb4
default-storage-engine=INNODB
innodb_buffer_pool_size = 200M
max_allowed_packet=16M
explicit_defaults_for_timestamp=1
log-output=FILE
general_log = 0
general_log_file=/usr/local/mysql/log/liandodb_general.err
slow_query_log = ON
slow_query_log_file=/usr/local/mysql/log/liandodb_query.err
long_query_time=10
log-error=/usr/local/mysql/log/liandodb_error.err
default-authentication-plugin=mysql_native_password
=======================================================
8.数据库初始化
[root@localhost mysql]# /usr/local/mysql/bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql/ –datadir=/usr/local/mysql/data/
=======================================================
9.查看初始化日志—–这里关键了啊,日志里边会有一个Mysql的临时密码一定要记下来。
[root@localhost mysql]# cd /usr/local/mysql/log/
[root@localhost log]# ls
liandodb_error.err liandodb_query.err (这是两个文件,不是命令)
[root@localhost log]# more liandodb_error.err (查看日志,记得将临时密码记在小本本上)
=======================================================
10.配置mysql服务
[root@localhost data]# vim /usr/lib/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=/usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf
LimitNOFILE = 65536
LimitNPROC = 65536
[root@localhost data]# systemctl daemon-reload
=======================================================
11.测试服务
[root@localhost ~]# systemctl stop mysqld
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# ps -ef | grep mysqld
mysql 3986 1 4 11:37 ? 00:00:01 /usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf
=======================================================
12.设置开机启动
[root@localhost ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
=======================================================
13.查看服务状态
[root@localhost ~]# systemctl status mysqld
?.mysqld.service – MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-05-15 11:37:42 CST; 2min 1s ago
Docs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 3986 (mysqld)
CGroup: /system.slice/mysqld.service
?..3986 /usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf
May 15 11:37:42 liandoyun systemd[1]: Started MySQL Server.
=======================================================
14.修改root口令—–友情提示,下文命令中‘root’为修改Mysql的密码为root,大家可以改自己想要的密码。
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.20
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)
这就可以了,不点赞还等啥呢。
下班了,抽空下远程连接Mysql教程。