赞
踩
之前一直是在window上安装mysql,但是实际应用mysql都是安装在服务器上,所以记录一下
本文记录了两种方式来安装mysql
一、使用yum源方式安装
二、使用本地tar文件方式安装
MariaDB Server 是最流行的开源关系型数据库之一。它由 MySQL 的原始开发者制作,并保证保持开源。
在 CentOS 7 中默认安装有 MariaDB
可忽略,安装完成之后可以直接覆盖掉MariaDB。
[root@localhost /]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -qa|grep mariadb
由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件
[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
--2023-02-25 06:24:11-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.212.157.5
...
...
100%[=========================================================================>] 25,680 --.-K/s 用时 0s
2023-02-25 06:24:19 (180 MB/s) - 已保存 “mysql57-community-release-el7-11.noarch.rpm” [25680/25680])
[root@localhost ~]# ls
anaconda-ks.cfg mysql57-community-release-el7-11.noarch.rpm 模板 图片 下载 桌面
initial-setup-ks.cfg 公共 视频 文档 音乐
命令执行完成后会在 /etc/yum.repos.d/ 目录下生成两个repo文件
mysql-community.repo
mysql-community-source.repo
[root@localhost ~]# yum -y install mysql57-community-release-el7-11.noarch.rpm
已加载插件:fastestmirror, langpacks
正在检查 mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch
mysql57-community-release-el7-11.noarch.rpm 将被安装
...
...
已安装:
mysql57-community-release.noarch 0:el7-11
完毕!
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo mysql-community-source.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community.repo
[root@localhost ~]# yum -y install mysql-server
如果没有提示错误可忽略
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
mysql-community-common-5.7.41-1.el7.x86_64.rpm 的公钥尚未安装
mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm 的公钥尚未安装
失败的软件包是:mysql-community-libs-compat-5.7.41-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
运行命令:rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
在重新安装
运行命令
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重新安装
[root@localhost ~]# yum -y install mysql-server
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
在第一次登录时需要,登录后可修改密码
[root@localhost ~]# cat /var/log/mysqld.log | grep password
2023-02-25T12:00:58.723624Z 1 [Note] A temporary password is generated for root@localhost: 1!L#qo3?d6i=
密码为刚才获取的临时密码,即1!L#qo3?d6i=
[root@localhost ~]# mysql -u root -p
Enter password:
如果密码设置太简单,会提示错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wxq3012@';
Query OK, 0 rows affected (0.00 sec)
如果想要设置简单的密码:
set global validate_password_policy=0;
set global validate_password_length=6;
其中,validate_password_number_count
指定了密码中数据的长度,validate_password_special_char_count
指定了密码中特殊字符的长度,validate_password_mixed_case_count
指定了密码中大小字母的长度。
这些参数,默认值均为1,所以validate_password_length
最小值为4,如果你显性指定validate_password_length
的值小于4,尽管不会报错,但validate_password_length
的值将设为4。当然也有mysql不符合这种情况的情形。所以此文章或许可以帮助您。
在mysql命令行中输入
命令中的用%代表所有IP,如有需要,可换成指定IP
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Wxq3012@' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重启配置
[root@localhost ~]# firewall-cmd --reload
success
完结,撒花
MySQL安装包官方下载地址:https://dev.mysql.com/downloads/mysql/5.7.html
可以通过XFTP软件将安装包上传到服务器
[root@localhost /]# cd /
[root@localhost /]# mkdir tools
[root@localhost /]# mkdir az
[root@localhost /]# ls /tools/
mysql-5.7.41-linux-glibc2.12-x86_64.tar
MariaDB Server 是最流行的开源关系型数据库之一。它由 MySQL 的原始开发者制作,并保证保持开源。
在 CentOS 7 中默认安装有 MariaDB
[root@localhost /]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -qa|grep mariadb
[root@localhost /]# rpm -qa | grep mysql
[root@localhost /]# whereis mysql
[root@localhost /]# find / -name mysql
[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd | grep mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
解压下载的 mysql-5.7.41-linux-glibc2.12-x86_64.tar
文件后
得到 mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
文件
[root@localhost /]# mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
解压 mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
文件到 /az/ 文件夹
修改文件夹名称为 mysql5.7
[root@localhost az]# mv mysql-5.7.41-linux-glibc2.12-x86_64/ mysql5.7
[root@localhost az]# ls
mysql5.7
为了避免权限问题,更改 mysql5.7 目录下所有文件夹所属的用户组、用户以及权限
[root@localhost az]# chown -R mysql:mysql /az/mysql5.7/
[root@localhost az]# chmod -R 755 /az/mysql5.7/
**进入 /az/mysql5.7/bin/ 目录,编译安装并初始化 mysql **
务必记住数据库管理员临时密码
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/az/mysql5.7/data --basedir=/az/mysql5.7
2023-02-23T22:43:52.131986Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
...
...
2023-02-23T22:43:52.554378Z 1 [Note] A temporary password is generated for root@localhost: Pyq#VB8mieDS
[root@localhost bin]# vim /etc/my.cnf
[mysqld]
datadir=/az/mysql5.7/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
表名存储在磁盘是小写的,但是比较的时候是不区分大小写
lower_case_table_names=1
[root@localhost bin]# chmod -R 755 /etc/my.cnf
因为没有安装下/usr/local/mysql
目录下,所以需要修改成安装的/az/mysql5.7
目录。
[root@localhost bin]# vim /az/mysql5.7/support-files/mysql.server
[root@localhost ~]# ps -ef | grep mysql
root 2031 1778 0 06:27 pts/0 00:00:00 tar -x mysql-5.7.41-linux-glibc2.12-x86_64.tar
root 2396 1778 0 06:55 pts/0 00:00:00 grep --color=auto mysql
[root@localhost ~]# ps -ef | grep mysqld
root 2398 1778 0 06:55 pts/0 00:00:00 grep --color=auto mysqld
[root@localhost ~]# /az/mysql5.7/support-files/mysql.server start
Starting MySQL.Logging to '/az/mysql5.7/data/localhost.localdomain.err'.
SUCCESS!
[root@localhost ~]# ln -s /az/mysql5.7/support-files/mysql.server /etc/init.d/mysql
[root@localhost ~]# ln -s /az/mysql5.7/bin/mysql /usr/bin/mysql
[root@localhost ~]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]#
密码就是初始化时生成的临时密码
[root@localhost ~]# mysql -u root -p
Enter password:
mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost ~]# cp /az/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
赋予可执行权限
[root@localhost ~]# chmod +x /etc/init.d/mysqld
添加服务
[root@localhost ~]# chkconfig --add mysqld
显示服务列表
[root@localhost ~]# chkconfig --list
开放3306端口命令
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重启防火墙
[root@localhost ~]# firewall-cmd --reload
success
完结,撒花
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。