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
[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
相關文章
- Centos7安裝安裝部署dockerCentOSDocker
- CentOS7安裝php、安裝MySqlCentOSPHPMySql
- 安裝centos7最小化安裝CentOS
- CentOS7 安裝 memcacheCentOS
- CentOS7 安裝 dockerCentOSDocker
- CentOS7 安裝 MySQLCentOSMySql
- CentOS7安裝RedisCentOSRedis
- Centos7 安裝ffmpegCentOS
- centos7安裝protobufCentOS
- 4.1 CentOS7安裝CentOS
- CentOS7 安裝NginxCentOSNginx
- centos7 安裝pipCentOS
- Centos7安裝RabbitMQCentOSMQ
- centos7安裝dockerCentOSDocker
- centos7安裝iptablesCentOS
- CentOS7安裝xrdpCentOS
- centos7 安裝rocketmqCentOSMQ
- centos7 安裝 rcloneCentOS
- centos7安裝mysqlCentOSMySql
- Centos7 安裝 NginxCentOSNginx
- centos7安裝nginxCentOSNginx
- centos7安裝教程詳解 centos7安裝詳細步驟CentOS
- CentOS7 下安裝 ElasticsearchCentOSElasticsearch
- centos7下安裝ffmpegCentOS
- centos7 docker 安裝教程CentOSDocker
- vmware 線上安裝 CentOS7CentOS
- Centos7快速安裝RocketMQCentOSMQ
- centos7快速安裝dockerCentOSDocker
- CentOS7安裝wpsCentOS
- centOs7安裝最新dockerCentOSDocker
- centos7下安裝phpCentOSPHP
- centos7安裝composerCentOS
- centos7安裝supervisorCentOS
- CentOS7安裝OpenvswitchCentOS
- Centos7上安裝dockerCentOSDocker
- VirtualBox安裝Centos7CentOS
- centos7下docker安裝CentOSDocker
- centos7安裝HadoopCentOSHadoop