centos7安裝 mysql-8.0.16

環境

CentOS Linux release 7.6.1810 (Core)

mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz

解壓

[root@hadoop-2 software]# tar -vxf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz

重命名:改什麼隨意,可不改

[root@hadoop-2 software]# mv mysql-8.0.16-linux-glibc2.12-x86_64 mysql8.0

進入目錄,新建data文件

[root@hadoop-2 software]# cd mysql8.0/
[root@hadoop-2 mysql8.0]# mkdir data

新建my.cnf文件,加入內容

[root@hadoop-2 mysql8.0]# vim my.cnf

 文件內容


[mysqld]
port=3306
#user=mysql
socket=/tmp/mysql.sock
basedir=/opt/software/mysql8.0
datadir=/opt/software/mysql8.0/data
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid

 

初始化數據庫

[root@hadoop-2 mysql8.0]# ./bin/mysqld --initialize --user=mysql --basedir=/opt/software/mysql8.0/ --datadir=/opt/software/mysql8.0/data/
2020-12-11T15:16:39.682697Z 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-12-11T15:16:39.682766Z 0 [System] [MY-013169] [Server] /opt/software/mysql8.0/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 9281
2020-12-11T15:16:53.815049Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vapp_h_<s0R+
2020-12-11T15:16:56.389493Z 0 [System] [MY-013170] [Server] /opt/software/mysql8.0/bin/mysqld (mysqld 8.0.16) initializing of server has completed

特別注意:root@localhost: vapp_h_<s0R+

root@localhost:後面跟的是初始化密碼

這邊如果直接啓動會報錯,還有一個地方需要改的

[root@hadoop-2 etc]# vim /etc/init.d/mysql

需要把

basedir=
datadir=

--否則service mysql start 會報Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysql

 [root@hadoop-1 mysql8.0]# service mysql start
/etc/init.d/mysql: line 239: my_print_defaults: command not found
/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

兩個補充完整

#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/opt/software/mysql8.0
datadir=/opt/software/mysql8.0/data

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

啓動mysql服務

[root@hadoop-1 mysql8.0]# service mysql start
Starting MySQL......... SUCCESS!

登錄

[root@hadoop-2 mysql8.0]# bin/mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@hadoop-2 mysql8.0]# bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.16

Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.00 sec)

 

配置一下環境變量方便登錄

[root@hadoop-2 mysql8.0]# vim /etc/profile

#加入

export MYSQL_HOME=/opt/software/mysql8.0
export PATH=$MYSQL_HOME/bin:$PATH

[root@hadoop-2 mysql8.0]# source /etc/profile

成功......

 

問題:

這邊稍微注意一下本來my.cnf 填的是socket=/tmp/mysql/mysql.sock

但是登錄的時候一直報,所以乾脆就改了,否則的話還應該創建mysql文件夾並授權的

[root@hadoop-2 mysql8.0]# bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@hadoop-2 tmp]# mkdir mysql

[root@hadoop-2 tmp]# chmod -R 777 mysql/

查看讀了什麼地方的my.cnf,ps:有些時候可能會讀的其他地方的my.cnf,導致裏面的路徑不正確

[root@hadoop-2 mysql8.0]# bin/mysqld --verbose --help|grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
                      my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章