使用tar包的安装方式
卸载系统自带的Mariadb
[root@hdp265dnsnfs ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@hdp265dnsnfs ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
删除etc目录下的my.cnf文件,如果有的话
[root@hdp265dnsnfs ~]# rm -f /etc/my.cnf
检查mysql是否存在
[root@hdp265dnsnfs ~]# rpm -qa | grep mysql
[root@hdp265dnsnfs ~]#
检查mysql组和用户是否存在,如无创建
[root@hdp265dnsnfs ~]# cat /etc/group | grep mysql
[root@hdp265dnsnfs ~]# cat /etc/passwd | grep mysql
创建mysql用户组
[root@hdp265dnsnfs ~]# groupadd mysql
创建一个用户名为mysql的用户并加入mysql用户组
[root@hdp265dnsnfs ~]# useradd -g mysql mysql
制定password 为mysql
[root@hdp265dnsnfs ~]# passwd mysql
解压缩到/usr/local目录
[root@hdp265dnsnfs local]# cd /usr/local
[root@hdp265dnsnfs local]# tar -zxvf /opt/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local
[root@hdp265dnsnfs local]# mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql
更改所属的组和用户
[root@hdp265dnsnfs var]# chown -R mysql:mysql mysql/
[root@hdp265dnsnfs var]# cd mysql/
[root@hdp265dnsnfs mysql]# mkdir data
[root@hdp265dnsnfs mysql]# chown -R mysql:mysql data
在etc下新建配置文件my.cnf,并在该文件内添加以下配置
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
安装和初始化
[root@hdp265dnsnfs mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
报错:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:yum install -y libaio
[root@hdp265dnsnfs mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@hdp265dnsnfs mysql]# chmod 755 /etc/my.cnf
[root@hdp265dnsnfs mysql]# chmod +x /etc/init.d/mysqld
[root@hdp265dnsnfs mysql]# /etc/init.d/mysqld start
Shutting down MySQL… SUCCESS!
Starting MySQL. SUCCESS!
设置开机启动
[root@hdp265dnsnfs mysql]# chkconfig --level 35 mysqld on
[root@hdp265dnsnfs mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@hdp265dnsnfs mysql]# chkconfig --add mysqld
[root@hdp265dnsnfs mysql]# systemctl status mysqld
[root@hdp265dnsnfs mysql]# systemctl start mysqld
SUCCESS! MySQL running (4475)
编辑/etc/profile/
export PATH=$PATH:/usr/local/mysql/bin
[root@hdp265dnsnfs mysql]# source /etc/profile
获得初始密码
[root@hdp265dnsnfs bin]# cat /root/.mysql_secret
Password set for user ‘root@localhost’ at 2019-03-01 16:51:38
HuMe26qohN)g
使用初始密码登录
[root@hdp265dnsnfs 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.26
Copyright © 2000, 2017, 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(‘root’);
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
添加远程访问权限
mysql> use mysql;
mysql> select user,host from user;
mysql> create user ‘admin’@’%’ identified by ‘admin’;
mysql> grant all on . to ‘admin’@’%’ identified by ‘admin’;
mysql> select user,host from user;
mysql> flush privileges;
mysql> quit;
重启生效
[root@hdp265dnsnfs bin]# systemctl restart mysqld
[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart
Shutting down MySQL… SUCCESS!
Starting MySQL. SUCCESS!