002A-mysql安装

mysql安装

 MySQL社区版下载页面https://dev.mysql.com/downloads/mysql/

在这里插入图片描述

[root@mysql-host local ]#rz -e 

[root@mysql-host local ]#ll
total 838940
drwxr-xr-x. 2 root root         6 Apr 11  2018 bin
drwxr-xr-x. 2 root root         6 Apr 11  2018 etc
drwxr-xr-x. 2 root root         6 Apr 11  2018 games
drwxr-xr-x. 2 root root         6 Apr 11  2018 include
drwxr-xr-x. 2 root root         6 Apr 11  2018 lib
drwxr-xr-x. 2 root root         6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root         6 Apr 11  2018 libexec
-rw-r--r--  1 root root 859071704 Nov 17 11:40 mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
drwxr-xr-x. 2 root root         6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root        49 Aug 19  2018 share
drwxr-xr-x. 2 root root         6 Apr 11  2018 src
[root@mysql-host local ]#tar xf mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz 
[root@mysql-host local ]#mv mysql-8.0.22-linux-glibc2.12-x86_64 mysql
[root@mysql-host local ]#groupadd mysql              #创建mysql组
[root@mysql-host local ]#useradd mysql -g mysql      #创建mysql用户
[root@mysql-host local ]#chown -R mysql:mysql mysql  #更改mysql目录的用户和用户组分别为mysql,mysql
[root@mysql-host local ]#cd mysql/
[root@mysql-host mysql ]#mkdir data   #创建存放mysql数据库文件目录
[root@mysql-host mysql ]#chown mysql:mysql data
[root@mysql-host mysql ]#ll
total 384
drwx------  2 mysql mysql   4096 Sep 23 22:11 bin   #可执行二进制文件命令
drwxr-xr-x  2 mysql mysql      6 Nov 17 14:40 data  #创建的数据库文件目录
drwx------  2 mysql mysql     55 Sep 23 22:11 docs  #数据库说明文档目录
drwx------  3 mysql mysql    282 Sep 23 22:11 include #头文件(c语言)
drwx------  6 mysql mysql    201 Sep 23 22:11 lib     #lib库文件
-rw-r--r--  1 mysql mysql 378912 Sep 23 20:37 LICENSE #授权license文件
drwx------  4 mysql mysql     30 Sep 23 22:11 man     #man说明文档目录
-rw-r--r--  1 mysql mysql    687 Sep 23 20:37 README  #自述文件
drwx------ 28 mysql mysql   4096 Sep 23 22:11 share   #字符集信息,错误信息提示文件等
drwx------  2 mysql mysql     77 Sep 23 22:11 support-files  #支持文件,如已经写好的mysql启动服务脚本等

#初始化数据库目录,会生成data目录下的文件和一个登录root用户的临时密码,如果初始化后再次初始化,需要删除data目录下的文件
[root@mysql-host mysql ]#bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
2020-11-17T06:42:12.688848Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-11-17T06:42:12.688933Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.22) initializing of server in progress as process 3428
2020-11-17T06:42:12.698300Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-17T06:42:13.243660Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-11-17T06:42:14.487465Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dz2e-V/D*p=H

#启动mysql服务
[root@mysql-host mysql ]#bin/mysqld_safe --initialize --user=mysql --datadir=/usr/local/mysql/data
2020-11-17T06:42:41.272319Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.

#删除配置文件后,使用mysql默认参数
[root@mysql-host mysql ]#rm -f /etc/my.cnf
[root@mysql-host mysql ]#bin/mysqld_safe --initialize --user=mysql --datadir=/usr/local/mysql/data
Logging to '/usr/local/mysql/data/mysql-host.err'.
2020-11-17T06:43:01.525094Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2020-11-17T06:43:01.565327Z mysqld_safe mysqld from pid file /usr/local/mysql/data/mysql-host.pid ended

#还可以通过服务启动mysql,默认查找/etc/my.cnf中指定的参数
[root@mysql-host mysql ]#./support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql-host.err'.
. SUCCESS! 

#主进程和子进程,共2个进程
[root@mysql-host mysql ]#
[root@mysql-host mysql ]#ps -ef |grep mysql
root       4489      1  0 15:26 pts/3    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql-host.pid
mysql      4574   4489  0 15:26 pts/3    00:00:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysq/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql-host.err --pid-file=/usr/local/mysql/data/mysql-host.pid
root       5059   3239  0 15:45 pts/4    00:00:00 grep --color=auto mysql
[root@mysql-host mysql ]#

[root@mysql-host share ]#mysql -u root -p
bash: mysql: command not found...
[root@mysql-host share ]#vi /root/.bash_profile 
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@mysql-host share ]#source /root/.bash_profile

[root@mysql-host share ]#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.22

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> 
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#如下命令5.7版本支持,5.8版本不在支持
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
mysql> 
mysql> 
mysql> alter user user() identified by 'mysql';
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
[root@mysql-host share ]#mysql -u root -pmysql
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 9
Server version: 8.0.22 MySQL Community Server - GPL

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

如果将/usr/local/mysql/下的data目录移到别的目录下,mysql服务启动会报错,需要vim /etc/my.cnf添加如下一行
[mysqld]
datadir=目录路径
数据和程序文件不在同一个目录或者硬盘

如果将mysql整个安装目录从/usr/local/mysql移到别处,需要vim /etc/my.cnf添加如下
[mysqld]
basedir=/usr/local/mysql2
datadir=/usr/local/mysql2/data

多实例启动mysql

[root@mysql-host local ]#cp -R mysql mysql2

[root@mysql-host mysql ]#vim /etc/my3307.cnf
[mysqld]
basedir=/usr/local/mysql2
datadir=/usr/local/mysql2/data
port=3307
socket=/tmp/mysql3307.sock
mysqlx_port=33070
mysqlx_socket=/tmp/mysqlx33070.sock

配置文件参数参考mysql第一个实例如下

[root@mysql-host ~ ]#mysql -u root -pmysql
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 11
Server version: 8.0.22 MySQL Community Server - GPL

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> 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)

#查看3306和33060
[root@mysql-host mysql ]#netstat -an | grep -i listen
tcp        0      0 127.0.0.1:6012          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6013          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:41051           0.0.0.0:*               LISTEN     
tcp6       0      0 ::1:6012                :::*                    LISTEN     
tcp6       0      0 ::1:6013                :::*                    LISTEN     
tcp6       0      0 :::32894                :::*                    LISTEN     
tcp6       0      0 :::33060                :::*                    LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN  

启动mysql2

[root@mysql-host mysql2 ]#bin/mysqld --defaults-file=/etc/my3307.cnf --user=mysql &
[1] 5313
[root@mysql-host mysql2 ]#2020-11-17T07:57:13.281982Z 0 [System] [MY-010116] [Server] /usr/local/mysql2/bin/mysqld (mysqld 8.0.22) starting as process 5313
2020-11-17T07:57:13.291225Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-17T07:57:13.509495Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-11-17T07:57:13.633706Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33070, socket: /tmp/mysqlx33070.sock
2020-11-17T07:57:13.762323Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-11-17T07:57:13.762573Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-11-17T07:57:13.809469Z 0 [System] [MY-010931] [Server] /usr/local/mysql2/bin/mysqld: ready for connections. Version: '8.0.22'  socket: '/tmp/mysql3307.sock'  port: 3307  MySQL Community Server - GPL.


[root@mysql-host tmp ]#ll
total 20
srwxrwxrwx  1 mysql mysql   0 Nov 17 15:57 mysql3307.sock
-rw-------  1 mysql mysql   5 Nov 17 15:57 mysql3307.sock.lock
srwxrwxrwx  1 mysql mysql   0 Nov 17 15:26 mysql.sock
-rw-------  1 mysql mysql   5 Nov 17 15:26 mysql.sock.lock
srwxrwxrwx  1 mysql mysql   0 Nov 17 15:57 mysqlx33070.sock
-rw-------  1 mysql mysql   6 Nov 17 15:57 mysqlx33070.sock.lock
srwxrwxrwx  1 mysql mysql   0 Nov 17 15:26 mysqlx.sock
-rw-------  1 mysql mysql   6 Nov 17 15:26 mysqlx.sock.lock
drwx------  2 root  root   24 Nov 17 13:49 ssh-iMEk9ZHDIYBY
drwx------  3 root  root   17 Nov 17 13:49 systemd-private-ff268a8040cf4318ada7245b116d3f6d-chronyd.service-uaNw2E
drwx------  3 root  root   17 Nov 17 13:49 systemd-private-ff268a8040cf4318ada7245b116d3f6d-colord.service-JQ98i9
drwx------  3 root  root   17 Nov 17 13:49 systemd-private-ff268a8040cf4318ada7245b116d3f6d-cups.service-k35GeP
drwx------  3 root  root   17 Nov 17 13:49 systemd-private-ff268a8040cf4318ada7245b116d3f6d-rtkit-daemon.service-nHuV2F
drwx------. 2 root  root    6 Nov 17 15:31 tracker-extract-files.0
-rw-------  1 root  root  617 Nov 17 14:39 yum_save_tx.2020-11-17.14-39.V4Ue6y.yumtx
[root@mysql-host tmp ]#mysql -u root -p -S /tmp/mysql3307.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22 MySQL Community Server - GPL

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> show variables like "%sock%";
+-----------------------------------------+-----------------------+
| Variable_name                           | Value                 |
+-----------------------------------------+-----------------------+
| mysqlx_socket                           | /tmp/mysqlx33070.sock |
| performance_schema_max_socket_classes   | 10                    |
| performance_schema_max_socket_instances | -1                    |
| socket                                  | /tmp/mysql3307.sock   |
+-----------------------------------------+-----------------------+
4 rows in set (0.02 sec)

mysql> 


#第二个实例以一个单独进程运行
[root@mysql-host mysql2 ]#ps -ef |grep mysql
root       4489      1  0 15:26 pts/3    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql-host.pid
mysql      4574   4489  0 15:26 pts/3    00:00:05 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysq/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql-host.err --pid-file=/usr/local/mysql/data/mysql-host.pid
mysql      5313   3200  0 15:57 pts/3    00:00:01 bin/mysqld --defaults-file=/etc/my3307.cnf --user=mysql
root       5381   3239  0 15:59 pts/4    00:00:00 mysql -u root -p -S /tmp/mysql3307.sock
root       5447   3200  0 16:03 pts/3    00:00:00 grep --color=auto mysql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值