#卸载系统自带的Mariadb
[root@ ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
#删除etc目录下的my.cnf文件
[root@ ~]# rm -rf /etc/my.cnf
#检查mysql是否存在
[root@ ~]# rpm -qa | grep mysql
[root@ ~]#
#检查mysql组和用户是否存在,如无创建
[root@ ~]# cat /etc/group | grep mysql
[root@ ~]# cat /etc/passwd | grep mysql
#创建mysql用户组
[root@ ~]# groupadd mysql
#创建一个用户名为mysql的用户并加入mysql用户组
[root@ ~]# useradd -g mysql mysql
#制定password 为1
[root@~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
#由于我的/usr/local空间不足,所以我安装到/var
[root@ var]# tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@ var]# mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
#更改所属的组和用户
[root@ var]# cd mysql/
[root@ mysql57]# mkdir data
[root@ var]# chown -R mysql.mysql mysql/
安装和初始化
[root@ mysql]# bin/mysql_install_db --user=mysql --basedir=/var/mysql/ --datadir=/var/mysql/data/
[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
[WARNING] The bootstrap log isn't empty:
[Warning] --bootstrap is deprecated. Please consider using --initialize instead
[Warning] Changed limits: max_open_files: 1024 (requested 5000)
[Warning] Changed limits: table_open_cache: 407 (requested 2000)
修改/support-files/mysql.server文件的basedir和datadir目录路径为我们环境所在的mysql的basedir和datadir路径,指定pid位置
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
mysqld_pid_file_path=/usr/local/mysql/data/mysql.pid
在etc下新建配置文件my.cnf,并在该文件内添加以下配置
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/mydata/mysql-5.7
# 设置mysql数据库的数据的存放目录
datadir=/mydata/mysql-5.7/data
# 允许最大连接数
max_connections=1000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
max_allowed_packet=16M
socket=/mydata/mysql-5.7/mysql.sock
#慢日志位置
slow_query_log_file=/mydata/mysql-5.7/log/slow_query.log
#慢日志时间
long_query_time=1
#开启慢日志
slow_query_log=TRUE
#
#
[mysqld_safe]
socket = /mydata/mysql-5.7/mysql.sock
[client]
socket = /mydata/mysql-5.7/mysql.sock
[mysql.server]
socket = /mydata/mysql-5.7/mysql.sock
[root@ mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@ mysql]# chown 777 /etc/my.cnf
[root@ mysql]# chmod +x /etc/init.d/mysqld
[root@ mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
#设置开机启动
[root@ mysql]# chkconfig --add mysqld
[root@ mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@ mysql]# chkconfig --add mysqld
[root@ mysql]# chkconfig --list mysqld
[root@ mysql]# service mysqld status
SUCCESS! MySQL running (4475)
etc/profile/
export PATH=$PATH:/var/mysql/bin
[root@hdp265dnsnfs mysql57]# source /etc/profile 设置环境变量后,mysql可以再任意目录登录
获得初始密码
[root@hdp265dnsnfs bin]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2018-05-31 16:30:15
dzoS>E3!+3M7
修改密码
[root@ bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> set PASSWORD = PASSWORD('666666');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
把mysql客户端放到默认路径
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql