centos7 mysql5.7 包解压安装

#卸载系统自带的Mariadb
rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

#删除etc目录下的my.cnf文件

rm /etc/my.cnf
rm: cannot remove ?etc/my.cnf? No such file or directory

#检查mysql是否存在
rpm -qa | grep mysql
#若存在卸载以前的mysql
rpm -e 已经存在的MySQL全名

#检查mysql组和用户是否存在,如无创建
cat /etc/group | grep mysql 
cat /etc/passwd | grep mysql

#创建mysql用户组
groupadd mysql
#创建一个用户名为mysql的用户并加入mysql用户组
useradd -g mysql mysql
#设置password
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.

#下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
#若报-bash: wget: command not found,则表明没有安装wget,需要安装,安装命令如下:
yum -y install wget

#解压文件
tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
cd /usr/local/
#文件名修改为mysql:
mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql

#更改所属的组和用户
chown -R mysql mysql/
chgrp -R mysql mysql/
cd mysql/
mkdir data
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

#初始化数据库
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#初始化后会生成一个临时密码 root@localhost::*(最好先记录这个临时密码)

cp ./support-files/mysql.server /etc/init.d/mysqld
chown 777 /etc/my.cnf 
chmod +x /etc/init.d/mysqld

#启动mysql
./mysqld_safe --user=mysql &



## 修改密码
./mysql -uroot -p
Enter password:这里输入之前的临时密码
mysql> set password=password('新密码');

#设置远程访问账号:grant all privileges on . to 远程访问用户名@’%’ identified by ‘用户密码’;
# 此处的密码是远程连接的密码跟刚刚设置的本地密码可以不一样,远程连接用于 MysqlWorkBench 等连接管理
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql> flush privileges;

#到相应的云平台设置安全组,开发入站端口3306

posted on 2018-12-14 11:04  淫光蝎子  阅读(590)  评论(0)    收藏  举报