当前位置:   article > 正文

Linux Mysql 8.0 安装_mysql ver 8.0.24版本linux下载安装教程

mysql ver 8.0.24版本linux下载安装教程

单实例Mysql

1、rz本地tar包到虚拟机并解压

[root@lb ~]# rz mysql-8.0.24-el7-x86_64.tar.gz 
[root@lb ~]# tar zxf mysql-8.0.24-el7-x86_64.tar.gz

2、卸载mariadb以及相关配置文件

[root@lb ~]# rpm -e mariadb-libs postfix

3、检查是否还有my.cnf文件

ll /etc | grep my.cnf | grep -e grep 

4、移动mysql解压文件 到你想要的目录 并重命名 (本人移动到home下)

[root@lb ~]# mv mysql-8.0.24-el7-x86_64 /home/mysql
[root@lb ~]# cd /home/
[root@lb home]# ls
kin1  mysql

5、创建myql组以及用户

[root@lb home]# groupadd mysql
[root@lb home]# useradd mysql -g mysql
#删除用户和组用对应命令
groupdel mysql
userdel mysql 

6、进入目录、创建data数据目录并授权data权限

[root@lb home]# cd mysql/
[root@lb mysql]# mkdir data
[root@lb mysql]# chown mysql:mysql data

 

7、进入data目录,此时是空的

 

如果默认初始化 是默认在/usr/local/mysql/data下

此时需要设置配置文件/etc/my.cnf(需要自己创建并写入)

[root@lb data]# vim /etc/my.cnf
[mysqld]
datadir = /home/mysql/data
basedir = /home/mysql

8、保存并退出到/home/mysql目录下进行初始化

[root@lb mysql]# bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data 
2021-12-03T18:30:34.798344Z 0 [System] [MY-013169] [Server] /home/mysql/bin/mysqld (mysqld 8.0.24) initializing of server in progress as process 71059
2021-12-03T18:30:34.844889Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-12-03T18:30:36.095826Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-12-03T18:30:37.954270Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7WFs9Uk+MGgL #mysql临时密码
#得到密码 7WFs9Uk+MGgL
#如果忘了密码,在data下没有其他数据的情况下,可以先删除data下的所有文件,再次初始化

9、拷贝mysql启动命令到/etc/init.d下,并更改名称(可不更改)。

[root@lb mysql]# ls
bin  data  docs  include  lib  LICENSE  man  README  share  support-files
[root@lb mysql]# cp support-files/mysql.server /etc/init.d/mysql

10、启动myql并检查端口

[root@lb mysql]# /etc/init.d/mysql start 
Starting MySQL.Logging to '/home/mysql/data/lb.err'.
.. SUCCESS! 
[root@lb mysql]# netstat -ltunp| grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      71328/mysqld        
tcp6       0      0 :::33060                :::*                    LISTEN      71328/mysqld 

11、进入mysql,会报错

[root@lb mysql]# mysql -u root -p
bash: mysql: command not found...
#不是你安装的问题,是环境变量里没有指定路径

12、修改环境变量路径,保存退出并且刷新变量

[root@lb mysql]# cd bin/
[root@lb bin]# pwd
/home/mysql/bin
[root@lb bin]# vim ~/.bash_profile 
# .bash_profile
​
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
​
# User specific environment and startup programs
​
PATH=$PATH:$HOME/bin:/home/mysql/bin
​
export PATH
# PATH=$PATH:$HOME/bin后面添加了:/home/mysql/bin
​
[root@lb bin]# source ~/.bash_profile 

13、进入mysql 并使用初始化的临时密码

[root@lb bin]# mysql -u root -p    #  7WFs9Uk+MGgL
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24
​
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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.#在执行此语句之前,必须使用ALTER USER语句重置密码

执行命令

mysql> set password=password('mysql');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password('mysql')' at line 1  #5.7版本之前都能用这个命令,但是8以后就不支持了
​
mysql> alter user user() identified by 'mysql';
Query OK, 0 rows affected (0.04 sec) #8.0以后使用alter命令更改密码

14、启动过程如果碰到如下报错

[root@lb mysql]# bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
bin/mysqld:error while loading shared libraies:libaio.so.1:cannot open shared object file:No such file or directory

则需要安装包

yum install -y libaio

启动多实例mysql

1、复制之前的mysql目录

[root@lb home]# cp mysql mysql2 -R

2、授权mysql2的data权限

由于是复制,data用户和组变更成root

[root@lb mysql2]# ll
total 292
drwxr-xr-x.  2 root root   4096 Dec  3 11:01 bin
drwxr-xr-x.  6 root root   4096 Dec  3 11:01 data
drwxr-xr-x.  2 root root     55 Dec  3 11:01 docs
drwxr-xr-x.  3 root root   4096 Dec  3 11:01 include
drwxr-xr-x.  6 root root    201 Dec  3 11:01 lib
-rw-r--r--.  1 root root 274942 Dec  3 11:01 LICENSE
drwxr-xr-x.  4 root root     30 Dec  3 11:01 man
-rw-r--r--.  1 root root    666 Dec  3 11:01 README
drwxr-xr-x. 28 root root   4096 Dec  3 11:01 share
drwxr-xr-x.  2 root root     77 Dec  3 11:01 support-files
​
[root@lb mysql2]# chown mysql:mysql data
[root@lb mysql2]# ll
total 292
drwxr-xr-x.  2 root  root    4096 Dec  3 11:01 bin
drwxr-xr-x.  6 mysql mysql   4096 Dec  3 11:01 data
drwxr-xr-x.  2 root  root      55 Dec  3 11:01 docs
drwxr-xr-x.  3 root  root    4096 Dec  3 11:01 include
drwxr-xr-x.  6 root  root     201 Dec  3 11:01 lib
-rw-r--r--.  1 root  root  274942 Dec  3 11:01 LICENSE
drwxr-xr-x.  4 root  root      30 Dec  3 11:01 man
-rw-r--r--.  1 root  root     666 Dec  3 11:01 README
drwxr-xr-x. 28 root  root    4096 Dec  3 11:01 share
drwxr-xr-x.  2 root  root      77 Dec  3 11:01 support-files

先查看原先mysql的sock文件

mysql> show variables like '%sock%';
+-----------------------------------------+------------------+
| Variable_name                           | Value            |
+-----------------------------------------+------------------+
| mysqlx_socket                           | /tmp/mysqlx.sock |
| performance_schema_max_socket_classes   | 10               |
| performance_schema_max_socket_instances | -1               |
| socket                                  | /tmp/mysql.sock  |
+-----------------------------------------+------------------+
4 rows in set (0.01 sec)
#1、原先的配置文件默认的是 /tmp/mysql.sock文件
#2、mysqlx_socket 会启动一个33060端口

 

所以启动多实例需要增加2个配置

3、增加mysql2的配置文件my3307.cnf

[root@lb mysql2]# vim /etc/my3307.cnf
[mysqld]
basedir = /home/mysql2
datadir = /home/mysql2/data
port = 3307
socket = /tmp/mysql3307.sock
mysqlx_port = 33070
mysqlx_socket = /tmp/mysqlx3307.sock

由于是拷贝过来的,所以不需要重新初始化

[root@lb mysql2]# bin/mysqld --defaults-file=/etc/my3307.cnf --user=mysql &
[1] 71995
[root@lb mysql2]# 2021-12-03T19:18:31.798791Z 0 [System] [MY-010116] [Server] /home/mysql2/bin/mysqld (mysqld 8.0.24) starting as process 71995

 

如果没有成功,请再重新给与mysql2下data用户组以及用户

[root@lb mysql2]# chown mysql:mysql data -R

4、连接3307端口的Mysql

mysql -u root -p -S /tmp/mysql3307.sock
#密码跟mysql一样:mysql

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/554015
推荐阅读
相关标签
  

闽ICP备14008679号