centos安装MySQL8记录
1. 卸载mariadb
因centos7默认安装了mariadb, 会造成依赖冲突,按下列方式进行卸载:
rpm -qa | grep mariadb
#如果出现
mariadb-libs-5.5.68-1.el7.x86_64
#执行
rpm -e mariadb-libs --nodeps
2. 下载 注意权限: ( https://downloads.mysql.com/archives/community/ )
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar 失效
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
#下载完后创建目标文件夹,将其解压
tar -xvf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.0.30-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm
mysql-community-common-8.0.30-1.el7.x86_64.rpm
mysql-community-devel-8.0.30-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.30-1.el7.x86_64.rpm
mysql-community-libs-8.0.30-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.30-1.el7.x86_64.rpm
mysql-community-server-8.0.30-1.el7.x86_64.rpm
mysql-community-test-8.0.30-1.el7.x86_64.rpm
3. 安装 (yum install -y perl.x86_64 ??)
rpm -ivh mysql-community-common-8.0.30-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-8.0.30-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-8.0.30-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-icu-data-files-8.0.30-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-8.0.30-1.el7.x86_64.rpm --force --nodeps
注意权限:(chmod -R 777 /var/lib/mysql)(chmod -R 777 /var/lib/mysql)
安装或者配置报错 .....libaio.so.1.... 则安装 yum install -y libaio, 重新执行即可
4.设置开机自启动 systemctl enable mysqld.service
4. 启动 systemctl start mysqld
6. 修改密码
#查看初始密码
grep 'temporary password' /var/log/mysqld.log
#登录、使用刚才的获得的密码
mysql -uroot -p
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
#MySQL 8.0 调整密码验证规则(否则设置简单密码不成功):
set global validate_password.policy=0;
set global validate_password.length=1;
7. 设置mysql远程链接
#登录MySQL 运行以下指令 use mysql
update user set host='%' where user='root'
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
防火墙 firewall-cmd --permanent --zone=public --add-port=3306/tcp systemctl reload firewalld
参考:https://www.bilibili.com/read/cv22423344/
8. mysql密码忘记,centos重置mysql密码
1.添加无需密码登录 vim /etc/my.cnf 在[mysqld]下一行添加 skip-grant-tables
2. 重启mysql服务 systemctl restart mysqld.service 或者 sudo systemctl restart mysqld
3. 登录后,重置密码 mysql -uroot -p 回车 ,
FLUSH PRIVILEGES;
ALTER USER 'root'@'%' IDENTIFIED BY 'root';
4. 改回配置文件,重启mysql服务
9.卸载mysql
1.查看安装的mysql组件 rpm -qa | grep -i mysql
2.卸载mysql rpm -ev mysql-community-server-5.7.30-1.el7.x86_64
3.删除多余的文件夹 find / -name mysql rm -rf /usr/share/mysql
2024-06-10 Windows mysql zip安装;
1.下载https://downloads.mysql.com/archives/community/
2.解压到自己需要的位置,并在根目录创建data文件夹和my.ini文件
my.ini文件内容如下
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=C:\develop\mysql5.7
# 设置mysql数据库的数据的存放目录
datadir=C:\develop\mysql5.7\data
# 允许最大连接数
max_connections=20
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names = 1
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
3.配置环境变量;path中加上 C:\develop\mysql5.7
4.初始化数据库 输入cmd,以管理员身份运行,进入MySQL路径(C:\develop\mysql5.7\bin)下,运行 mysqld --initialize --console
4.上面执行结果,记录密码。 (后期修改初始密码,远程权限等设置即可)。
5.服务安装和启动:mysqld --install mysql; net start mysql;