浏览器地址栏输入网址:https://mysql.com——>选择DOWNLOADS下滑找到MySQL Community (GPL) Downloads ——>MySQL Community Downloads——>MySQL Community Server——>Archives——>选择数据库版本、操作系统类型(windows、linux)、版本(windows7、CentOS7) Product Version、Operating System、OS Version——>RPM Bundle——>Download
2、建立目录
mkdir /opt/mysql-5.7.36
3、解压
tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar -C ./mysql-5.7.36
yum list installed | grep mariadb
rpm -qa | grep mariadb
yum -y remove mariadb-libs.x86_64
rpm -e --nodeps mariadb-libs.x86_64
3.安装MySQL5.7.36
cd /opt/msyql-5.7.36
rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm
which mysqld
/usr/sbin/mysqld --verbose --help | grep -A 1 'Default options'
vi /etc/my.cnf
编辑文件(如果发现是新文件,则编辑后面的文件)
在[mysqld]下面加入 lower_case_table_names=1 (不区分表名大小写)
systemctl start mysqld.service
查看mysql状态
systemctl status mysqld.service
查看临时密码
grep 'temporary password' /var/log/mysqld.log
cat /var/log/mysqld.log | grep temp
mysql -uroot -p
set global validate_password_policy=0;
修改有效密码长度
set global validate_password_length=4;
重设密码
set password for root@localhost=password('123456');
6.授予root用户远程访问权限
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;
7. 修改数据库存储位置
Mysql通过rpm包安装后数据存储默认位置为:/var/lib/mysql。如果/var/lib的存储空间太小,则需要我们迁移数据库的数据存储路径。
(1)关闭mysql服务
systemctl stop mysqld.service
(2)新建自己的数据存储路径文件夹
mkdir /opt/mysqldata
(3)将/var/lib/mysql拷贝到/opt/mysqldata,并修改文件夹的属组
cp -a /var/lib/mysql/ /opt/mysqldata/
chown mysql:mysql /opt/mysqldata/mysql
授予新的文件夹权限
chmod -R 777 /opt/mysqldata/
(4)修改mysql的配置文件
vi /etc/my.cnf
将原来mysql文件中的部分配置注释掉,添加以下配置
[mysqld]
socket=/opt/mysqldata/mysql/mysql.sock
datadir=/opt/mysqldata/mysql
lower_case_table_names=1
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=1000
innodb_buffer_pool_size = 2048M
innodb_large_prefix=1
innodb_file_format=barracuda
innodb_file_format_max=barracuda
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/opt/mysqldata/mysql/mysql.sock
[mysqld_safe]
socket=/opt/mysqldata/mysql/mysql.sock
[mysql.server]
socket=/opt/mysqldata/mysql/mysql.sock
(5)启动mysql
systemctl start mysqld.service
(6)测试是否成功
新增数据库XX
切换到/opt/mysqldata/mysql文件夹下,输入du -h --max-depth=1 /opt/mysqldata/mysql,可以看到XX数据库占用了188K.切换到/var/lib/mysql文件夹下,输入du -h --max-depth=1 /var/lib/mysql,发现没有ZC数据库.
mysql -uroot -p