目录
1、单机安装mysql8
下载最新版mysql8
安装包下载:MySQL :: Download MySQL Community Serverhttps://dev.mysql.com/downloads/mysql/
检查并卸载旧版mysql和mariadb
rpm -qa|grep mysql
rpm -qa|grep mariadb
如果有的话卸载掉
如:sudo rpm -ev --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
安装mysql8
解压压缩包
tar -xvf mysql-8.0.31-1.el9.x86_64.rpm-bundle.tar
开始安装
rpm -ivh mysql-community-common-8.0.31-1.el9.x86_64.rpm \
mysql-community-client-plugins-8.0.31-1.el9.x86_64.rpm \
mysql-community-client-8.0.31-1.el9.x86_64.rpm \
mysql-community-libs-8.0.31-1.el9.x86_64.rpm \
mysql-community-icu-data-files-8.0.31-1.el9.x86_64.rpm \
mysql-community-server-8.0.31-1.el9.x86_64.rpm
设置表名字段名大小写不敏感(初始化数据前修改)
(设置前不要启动数据库) 编辑my.cnf文件
vi /etc/my.cnf最后一行增加
lower_case_table_names=1
启动数据库
sudo systemctl start mysqld
查看数据库启动状态
sudo systemctl status mysqld
设置数据库开机自启动
sudo systemctl enable mysqld
关闭防火墙
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
或开放防火墙端口
查看数据库初始的随机密码
sudo cat /var/log/mysqld.log | grep password
初始随机密码为:w_jH7sL/mqp;
登录mysql修改root密码
mysql -u root -p
修改密码
alter USER 'root'@'localhost' IDENTIFIED BY 'Root.123456';
授权远程连接
登录MySQL
mysql -u root -p
命令:show databases;
命令:use mysql;
命令:select host, user, authentication_string, plugin from user;
命令:update user set host = "%" where user='root';
命令:select host, user, authentication_string, plugin from user;
命令:flush privileges;
修改数据库默认存储路和默认端口号
查看MySQL的数据存储路径
mysqladmin -u root -p variables | grep datadir
停止mysql
systemctl stop mysqld
创建新的存储
mkdir /data/mysqldb
将默认的数据文件移动到新的存储路径中
mv /var/lib/mysql /data/mysqldb/
使用管理员权限 编辑/etc/my.cnf文件
sudo vi /etc/my.cnf在[mysqld]里添加
port 3309
将datadir=/var/lib/mysql修改成
datadir=/data/mysqldb/mysql
将socket=/var/lib/mysql/mysql.sock修改成socket=/data/mysqldb/mysql/mysql.sock
启动mysql
systemctl start mysqld