1、软件包下载(下载至本地,上传至linux目录,本人一般上传至/usr/local/src/目录下):
根据Linux的位数,请下载合适的软件安装包:32位下载32位的安装包,64位下载64位的安装包
1.1 官网手动下载:
官网网址:MySQL :: Download MySQL Community Server
1.2 Linux镜像下载(下载至目录/usr/local/src/):
cd /usr/local/src/
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.27-linux-glibc2.12-x86_64.tar.gz
1.3卸载mariadb
(1)查看mariadb 的安装包
rpm -qa | grep mariadb
(2)卸载mariadb
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
(3)卸载验证:
rpm -qa | grep mariadb
2、安装
2.1 解压安装包
# 进入下载目录
/usr/local/src/
# 解压
tar -zxvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.gz
# 查看
ls
# 显示内容:
# mysql-8.0.27-linux-glibc2.12-x86_64 .....
# 移动解压后的文件夹至/usr/local
mv /usr/local/src/mysql-8.0.27-linux-glibc2.12-x86_64 /usr/local/
cd /usr/local/
# 重命名
mv ./mysql-8.0.27-linux-glibc2.12-x86_64 mysql-8.0
# 创建文件夹data,存储文件;
cd /usr/local/mysql-8.0/
mkdir ./data
2.2 创建用户及用户组
# 用户组
groupadd mysql
# 用户 (用户名/密码)
useradd -g mysql mysql
2.3 授权
chown -R mysql.mysql /usr/local/mysql-8.0/ # 亲测
或
chown -R mysql .
chgrp -R mysql .
2.4 初始化数据库:
# 查看当前所在目录
pwd # 若显示/usr/local/mysql-8.0,请继续执行,否则请先进入此目录/usr/local/mysql-8.0
# 初始化 注意查看是否存在相关目录,若不存在,请新建
./bin/mysqld --user=mysql --basedir=/usr/local/mysql-8.0/ --datadir=/usr/local/mysql-8.0/data/ --initialize ; # 亲测
或
./bin/mysql --user=mysql --basedir=/usr/local/mysql-8.0/ --datadir=/usr/local/mysql-8.0/data/ --initialize ;
注意:截图从上往下第12-13行生成的“临时密码”;
2.5 Mysql配置
vi /etc/my.cnf
2.6 建立MySQL服务
# 添加Mysql到系统服务
cp -a ./support-files/mysql.server /etc/init.d/mysql # 若mysqld,以下mysql相应的修改mysqld,如下图所示
chmod +x /etc/init.d/mysql
chkconfig --add mysql
# 检查服务是否生效
chkconfig --list mysql
3、启动Mysql服务
# 启动
service mysql start;
# 查看启动状态
service mysql status;
登陆Mysql:
# 登陆
mysql -uroot -p
# 输入"初始化数据库"操作时的"临时密码"
修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
4、远程连接
1.在 my.cnf 的mysqld 下增加
default_authentication_plugin=mysql_native_password
2.进入mysql命令行
use mysql
update user set host ='%' where user='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;
使用客户端工具进行连接。
参考链接:https://www.cnblogs.com/yg_zhang/p/10424926.html;
javax.jdo.option.ConnectionURL
jdbc:mysql://nns:3306/hivedbcreateDatabaseIfNotExist=true&useSSL=false&serverTimezone=UTC
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName
root
javax.jdo.option.ConnectionPassword
root
99、错误信息:
99.1、ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
[root@master mysql]# ll
total 308
drwxr-xr-x 2 mysql mysql 4096 Apr 24 2021 bin
drwxr-xr-x 6 mysql mysql 4096 Feb 17 15:54 data
drwxr-xr-x 2 mysql mysql 4096 Apr 24 2021 docs
drwxr-xr-x 3 mysql mysql 4096 Apr 24 2021 include
drwxr-xr-x 6 mysql mysql 4096 Apr 24 2021 lib
-rw-r--r-- 1 mysql mysql 274942 Apr 23 2021 LICENSE
drwxr-xr-x 4 mysql mysql 4096 Apr 24 2021 man
-rw-r--r-- 1 mysql mysql 666 Apr 23 2021 README
drwxr-xr-x 28 mysql mysql 4096 Apr 24 2021 share
drwxr-xr-x 2 mysql mysql 4096 Apr 24 2021 support-files
[root@master mysql]# sudo ./support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/master.err'.
[ OK ]
[root@master mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.25
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.