linux下安装mysql 8.0.13

阿里云Linux下安装mysql 8.0.13

1.下载安装包

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

2.解压

tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

3.改名字

mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql

4.移动位置,创建用户和用户组并授权

mv mysql /usr/local/
cd /usr/local/
ll
[root@linux local]# groupadd mysql
[root@linux local]# useradd -r -g mysql mysql
[root@linux local]# cd mysql/
#注意:进入mysql文件下授权所有的文件
[root@linux mysql]# ll
[root@linux mysql]# chown -R mysql:mysql ./
[root@linux mysql]# ll

5.创建data文件夹

[root@linux mysql]# mkdir data
[root@linux mysql]# ll

6.初始化数据库,(随机密码)

安装:yum -y install libaioyum -y install numactl

[root@linux mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

2020-04-17T08:47:38.623880Z 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-04-17T08:47:38.624038Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 10415
2020-04-17T08:47:42.359922Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dTMu)mewW06=
2020-04-17T08:47:44.048720Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed

随机密码:dTMu)mewW06=

7.修改/usr/local/mysql当前目录得用户

[root@linux mysql]# ll
total 468
drwxr-xr-x  2 mysql mysql   4096 Apr 17 16:41 bin
drwxr-xr-x  6 mysql mysql   4096 Apr 17 16:47 data
drwxr-xr-x  2 mysql mysql   4096 Apr 17 16:41 docs
drwxr-xr-x  3 mysql mysql   4096 Apr 17 16:40 include
drwxr-xr-x  6 mysql mysql   4096 Apr 17 16:41 lib
-rw-r--r--  1 mysql mysql 335809 Oct  7  2018 LICENSE
-rw-r--r--  1 mysql mysql 101807 Oct  7  2018 LICENSE.router
drwxr-xr-x  4 mysql mysql   4096 Apr 17 16:40 man
-rw-r--r--  1 mysql mysql    687 Oct  7  2018 README
-rw-r--r--  1 mysql mysql    700 Oct  7  2018 README.router
drwxr-xr-x 28 mysql mysql   4096 Apr 17 16:41 share
drwxr-xr-x  2 mysql mysql   4096 Apr 17 16:41 support-files

[root@linux mysql]# chown -R root:root ./
[root@linux mysql]# chown -R mysql:mysql data

[root@linux mysql]# ll
total 468
drwxr-xr-x  2 root  root    4096 Apr 17 16:41 bin
drwxr-xr-x  6 mysql mysql   4096 Apr 17 16:47 data
drwxr-xr-x  2 root  root    4096 Apr 17 16:41 docs
drwxr-xr-x  3 root  root    4096 Apr 17 16:40 include
drwxr-xr-x  6 root  root    4096 Apr 17 16:41 lib
-rw-r--r--  1 root  root  335809 Oct  7  2018 LICENSE
-rw-r--r--  1 root  root  101807 Oct  7  2018 LICENSE.router
drwxr-xr-x  4 root  root    4096 Apr 17 16:40 man
-rw-r--r--  1 root  root     687 Oct  7  2018 README
-rw-r--r--  1 root  root     700 Oct  7  2018 README.router
drwxr-xr-x 28 root  root    4096 Apr 17 16:41 share

8.配置权限 # chmod 777 ./my-default.cnf

[root@linux mysql]# cd support-files/
[root@linux support-files]# ll
total 24
-rw-r--r-- 1 root root   773 Oct  7  2018 magic
-rwxr-xr-x 1 root root  1061 Oct  7  2018 mysqld_multi.server
-rwxr-xr-x 1 root root  2048 Oct  7  2018 mysql-log-rotate
-rwxr-xr-x 1 root root 10576 Oct  7  2018 mysql.server

[root@linux support-files]# touch my-default.cnf
[root@linux support-files]# chmod 777 ./my-default.cnf

[root@linux support-files]# ll
total 24
-rw-r--r-- 1 root root   773 Oct  7  2018 magic
-rwxrwxrwx 1 root root     0 Apr 17 16:53 my-default.cnf
-rwxr-xr-x 1 root root  1061 Oct  7  2018 mysqld_multi.server
-rwxr-xr-x 1 root root  2048 Oct  7  2018 mysql-log-rotate
-rwxr-xr-x 1 root root 10576 Oct  7  2018 mysql.server

[root@linux support-files]# cd ../
[root@linux mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? 
[root@linux mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

出现错误,加/

[root@linux mysql]# \cp support-files/my-default.cnf /etc/my.cnf
[root@linux mysql]# 
[root@linux mysql]# vim /etc/my.cnf
[mysqld]
  
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
  
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
  
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 3306
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
  
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

9.开机自启,进入/usr/local/mysql/support-files进行设置

[root@linux mysql]# cd support-files/
[root@linux support-files]# ll
total 24
-rw-r--r-- 1 root root   773 Oct  7  2018 magic
-rwxrwxrwx 1 root root     0 Apr 17 16:53 my-default.cnf

[root@linux support-files]# chmod +x /etc/init.d/mysql
[root@linux support-files]# ll
total 24
-rw-r--r-- 1 root root   773 Oct  7  2018 magic
-rwxrwxrwx 1 root root     0 Apr 17 16:53 my-default.cnf
-rwxr-xr-x 1 root root  1061 Oct  7  2018 mysqld_multi.server
-rwxr-xr-x 1 root root  2048 Oct  7  2018 mysql-log-rotate
-rwxr-xr-x 1 root root 10576 Oct  7  2018 mysql.server

10.注册服务,查看

[root@linux support-files]# cd ..
[root@linux mysql]# chkconfig --add mysql
[root@linux mysql]# chkconfig --list mysql

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

11.etc/ld.so.conf要配置路径,不然报错

[root@linux mysql]# vim /etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/mysql/lib
~                                                                                                       
~ 

12.配置环境变量

[root@linux mysql]# vim /etc/profile

# /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib


[root@linux mysql]# source /etc/profile
[root@linux mysql]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/error.log'.
.                                                          [  OK  ]

13.登录

[root@linux mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13

Copyright (c) 2000, 2018, 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.

14.修改密码

mysql>  alter user 'root'@'localhost' identified by 'XXXXXXX';   
Query OK, 0 rows affected (0.09 sec)

15.开启Navicat远程连接

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root             | $A$005$t8Y<0i1
                                               ,E|P`ZT)zSQTUDAQ5V86TvCsNfx1TRQagWpjnmlUQy0vnAu7awf2 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> GRANT ALL ON *.* TO 'root'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '1234';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234'; 
Query OK, 0 rows affected (0.09 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye
[root@linux mysql]# service mysql restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL..                                           [  OK  ]

连接失败,改

[root@linux mysql]# mysql -uroot -p        
Enter password: 
mysql> use mysql
mysql> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| %         | root             | *A4B6157319038724E3560894F7F932C8886EBFCF                              | mysql_native_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> exit;
Bye
[root@linux mysql]# service mysql restart
Shutting down MySQL...                                     [  OK  ]
Starting MySQL..                                           [  OK  ]

16.连接成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值