首先,下载linux下的mysql安装包
可以进入以下下载地址:https://dev.mysql.com/downloads/mysql/
接下来进行数据库安装
首先要查看是否存在老的数据库
直接运行如下命令
---------------------------卸载老库,加粗部分对应上一条命令查询的版本---------------------------------
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
rm -rf /etc/selinux/targeted/active/modules/100/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
---------------------------进入放置安装包的目录,安装新库,直到配置文件---------------------------------
cd /data/mysql
tar -zvxf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.20-linux-glibc2.12-x86_64 ./mysql-5.7.20
rm -rf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
groupadd mysql
useradd mysql -g mysql
chown -R mysql .
chgrp -R mysql .
cd mysql-5.7.20/bin
vi /etc/my.cnf
---------------------------------下面为my.cnf添加更改的内容(位置根目录下 /etc/my.cnf)------------------------------------------
[mysql]
default-character-set=utf8
[mysqld]
port = 3306
basedir=/data/mysql/mysql-5.7.20/
datadir=/data/mysql/mysql-5.7.20/data
max_connections=8000
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=64M
--------------------------------------------修改mysql.server文件(位置:mysql下的support-files文件夹)------------------------------------------
vi ../support-files/mysql.server
--------------------------------------------修改mysql.server文件的以下参数------------------------------------------
basedir=/data/mysql/mysql-5.7.20/
datadir=/data/mysql/mysql-5.7.20/data
-------------------------------------------初始化(当前目录mysql下的bin)----------------------------------------------------------------
./mysqld --user=mysql --basedir=/data/mysql/mysql-5.7.20/ --datadir=/data/mysql/mysql-5.7.20/data --initialize
---------------------------此处生成一个随机密码,用于首次登陆数据库,位于输出信息最后,冒号后面所有(如:ca7#ZJwqT!Fz)---------------------------------
cd ../
./support-files/mysql.server start
./bin/mysql -uroot -p
---------------------------首次登陆数据库使用刚才生成的随机密码,然后进行密码修改,过程如下,我设置的密码为123456,最后可查看数据的字符集---------------------------------
set PASSWORD = PASSWORD('123456');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
show variables like '%char%';
quit;
----------------------------------mysqld文件配置------------------------------------------------
cp /data/mysql/mysql-5.7.20/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld restart
ln -s /data/mysql/mysql-5.7.20/bin/mysql /usr/bin
至此,mysql数据库安装完成。