快捷搜索:  汽车  科技

windows中mysql8.0.18.0安装教程(最新版mysql-8.0.26多实例部署)

windows中mysql8.0.18.0安装教程(最新版mysql-8.0.26多实例部署)

首先说明一下本文有参考了别人的方法,加入自己遇到的问题,及解决方法,整理以作记录。

最新版mysql-8.0.26多实例部署二进制文件下载 选用MySQL官网,--》MySQL Community Server-》Generic Linux-》linux-glibc2.12-x86_64选择mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

[root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz ....... [root@localhost local]# ls mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 创建用户和组,然后解压至 /usr/local目录下

#创建用户和组(我的系统因之前有装过一次,所有下面两步都提示已存在) [root@localhost ~]# groupadd -r mysql [root@localhost ~]# useradd -M -r -s /sbin/nologin -g mysql mysql #解压软件至/usr/local/ [root@localhost local]# tar xf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz -C /usr/local/ [root@localhost local]# cd /usr/local/mysql-8.0.26-linux-glibc2.12-x86_64 [root@localhost mysql-8.0.26-linux-glibc2.12-x86_64]# ls bin docs include lib LICENSE man README share support-files #创建软连接 [root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql [root@localhost local]# ll total 0 drwxr-xr-x. 2 root root 6 Nov 5 2016 bin drwxr-xr-x. 2 root root 6 Nov 5 2016 etc drwxr-xr-x. 2 root root 6 Nov 5 2016 games drwxr-xr-x. 2 root root 6 Nov 5 2016 include drwxr-xr-x. 2 root root 6 Nov 5 2016 lib drwxr-xr-x. 2 root root 6 Nov 5 2016 lib64 drwxr-xr-x. 2 root root 6 Nov 5 2016 libexec lrwxrwxrwx. 1 root root 35 Jan 10 16:05 mysql -> mysql-8.0.26-linux-glibc2.12-x86_64 drwxr-xr-x. 9 7161 31415 129 Jun 2 2020 mysql-8.0.26-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 Nov 5 2016 sbin drwxr-xr-x. 5 root root 49 Dec 24 13:10 share drwxr-xr-x. 2 root root 56 Jan 10 15:59 src #修改目录 /usr/local/mysql 的属主属组 [root@localhost local]# chown -R mysql.mysql /usr/local/mysql* [root@localhost local]# ll -d mysql lrwxrwxrwx. 1 mysql mysql 35 Jan 10 16:05 mysql -> mysql-8.0.26-linux-glibc2.12-x86_64 #配置环境变量 [root@localhost ~]# vim /etc/profile.d/mysql.sh [root@localhost ~]# cat /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH [root@localhost ~]# source /etc/profile.d/mysql.sh [root@localhost ~]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 创建各实例数据存放的目录

#创建多个数据存放目录 [root@localhost ~]# mkdir -p /opt/data/{3306 3307 3308} #授权 [root@localhost ~]# chown -R mysql.mysql /opt/data/ [root@localhost ~]# ll /opt/data/ total 0 drwxr-xr-x. 2 mysql mysql 6 Jan 10 16:10 3306 drwxr-xr-x. 2 mysql mysql 6 Jan 10 16:10 3307 drwxr-xr-x. 2 mysql mysql 6 Jan 10 16:10 3308 [root@localhost ~]# tree /opt/data/ /opt/data/ ├── 3306 ├── 3307 └── 3308 初始化各实例

#初始化3306实例 [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3306 --basedir=/usr/local/mysql 2021-01-10T08:18:53.784749Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-01-10T08:18:54.300749Z 0 [Warning] InnoDB: New log files created LSN=45790 2021-01-10T08:18:54.399807Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-01-10T08:18:54.416651Z 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: 7a7d7c56-531c-11eb-87a7-000c29decd5a. 2021-01-10T08:18:54.420048Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-01-10T08:18:55.945722Z 0 [Warning] CA certificate ca.pem is self signed. 2021-01-10T08:18:56.572819Z 1 [Note] A temporary password is generated for root@localhost: r4=aYD:fkigr [root@localhost ~]# echo 'r4=aYD:fkigr' > 3306-pass #初始化3307实例 [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3307 --basedir=/usr/local/mysql 2021-01-10T08:19:50.903564Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-01-10T08:19:51.400719Z 0 [Warning] InnoDB: New log files created LSN=45790 2021-01-10T08:19:51.472212Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-01-10T08:19:51.541330Z 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: 9c8a0685-531c-11eb-8950-000c29decd5a. 2021-01-10T08:19:51.543044Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-01-10T08:19:52.480641Z 0 [Warning] CA certificate ca.pem is self signed. 2021-01-10T08:19:53.130092Z 1 [Note] A temporary password is generated for root@localhost: 7Hpj>% AFS9K [root@localhost ~]# echo '7Hpj>% AFS9K' > 3307-pass #初始化3308实例 [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3308 --basedir=/usr/local/mysql 2021-01-10T08:20:34.279143Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-01-10T08:20:34.916792Z 0 [Warning] InnoDB: New log files created LSN=45790 2021-01-10T08:20:35.004523Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-01-10T08:20:35.098313Z 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: b6804a84-531c-11eb-8bf8-000c29decd5a. 2021-01-10T08:20:35.116655Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-01-10T08:20:36.520845Z 0 [Warning] CA certificate ca.pem is self signed. 2021-01-10T08:20:36.836153Z 1 [Note] A temporary password is generated for root@localhost: l4LsRt=Z>#00 [root@localhost ~]# echo 'l4LsRt=Z>#00' > 3308-pass 安装 perl(已有的可以略过)

[root@localhost ~]# yum install -y perl [root@localhost ~]# rpm -qa perl perl-5.16.3-297.el7.x86_64 修改配置文件 /etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf [mysqld_multi] mysqld=/usr/local/mysql/bin/mysqld_safe mysqladmin=/usr/local/mysql/bin/mysqladmin [mysqld3306] datadir=/opt/data/3306 socket=/tmp/mysql_3306.sock basedir=/usr/local/mysql port=3306 pid-file=/opt/data/3306/mysql_3306.pid character-set-server=utf8 log-error=/var/log/mysql_3306.log [mysqld3307] datadir=/opt/data/3307 socket=/tmp/mysql_3307.sock basedir=/usr/local/mysql port=3307 pid-file=/opt/data/3307/mysql_3307.pid character-set-server=utf8 log-error=/var/log/mysql_3307.log [mysqld3308] datadir=/opt/data/3308 socket=/tmp/mysql_3308.sock basedir=/usr/local/mysql port=3308 pid-file=/opt/data/3308/mysql_3308.pid character-set-server=utf8 log-error=/var/log/mysql_3308.log 启动3306、3307、3308实例

[root@localhost ~]# mysqld_multi start 3306 [root@localhost ~]# mysqld_multi start 3307 [root@localhost ~]# mysqld_multi start 3308 [root@localhost ~]# ss -antlp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* users:(("sshd" pid=1026 fd=3)) LISTEN 0 80 :::3307 :::* users:(("mysqld" pid=11061 fd=20)) LISTEN 0 80 :::3308 :::* users:(("mysqld" pid=11251 fd=20)) LISTEN 0 128 :::22 :::* users:(("sshd" pid=1026 fd=4)) LISTEN 0 80 :::3306 :::* users:(("mysqld" pid=10871 fd=20)) 初始化密码

[root@localhost ~]# cat 3306-pass r4=aYD:fkigr [root@localhost ~]# mysql -uroot -p'r4=aYD:fkigr' -S /tmp/mysql_3306.sock #这个地方我登录总是报错[root@localhost ~]# mysql -uroot -p'QRNziHAQA2%l'-S /tmp/mysql_3306.sock #mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory,后来查了资料,发现加个软连接就可以解决:sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5 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 2 Server version: 5.7.31 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> set password=password('123456'); #这个地方又报错: Query OK 0 rows affected 1 warning (0.00 sec) mysql> \q Bye

windows中mysql8.0.18.0安装教程(最新版mysql-8.0.26多实例部署)(1)

可以使用这个方式:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

Query OK 0 rows affected 1 warning (0.00 sec) mysql> \q Bye

以上,在配置my.cnf时发现有多种方式,灵活多变。参考CentOS7.3 部署两个实例 MySQL - muycode - 博客园 (cnblogs.com)一文中的内容:

windows中mysql8.0.18.0安装教程(最新版mysql-8.0.26多实例部署)(2)

之后,在启动实例方面也是灵活多变。以备后用。

猜您喜欢: