CentOS 7 安装Mysql 5.7

查看本机是否安装过mysql
ps -ef|grep mysql

列出mariadb
rpm -qa | grep mariadb
卸载MariaDB
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64
强制卸载MariaDB
rpm -e –-nodeps mariadb-libs-5.5.37-1.el7_0.x86_64
删除my.cnf
rm /etc/my.cnf

安装依赖包

yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison bison-devel
-y 表示安装过程勾选yes

1、软件下载

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.22.tar.gz

2、解压

tar命令 tar zxvf
– z – 过滤gzip文件,即只能解压缩指定的gz格式文件。
– x – 解压缩(tar还能进行压缩包查看和打包,所以如果需要解压缩文件包,需要在命令行中指定x)
– v – 以详细模式显示出解压缩的过程。
– f – 指定被解压缩的文件

3、预编译

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DWITH_BOOST=./boost/boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1

4、安装

make & make install
make clean

5、新建mysql用户与用户组

groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql
指定权限
chown -Rf mysql:mysql /usr/local/mysql

6、设置启动脚本,开机自启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#授予可执行权限
chmod +x /etc/init.d/mysqld
设置开机启动
systemctl enable mysqld

新建目录

mkdir /usr/local/data
/usr/local/logs
/usr/local/temp

7、初始化数据库

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#启动数据库
systemctl start mysqld

#查看状态
systemctl status mysqld

配置远程连接

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH PRIVILEGES;