LinuxCentos7安装mysql5.7详细教程【tar包安装】⼀. 准备资源
1.准备资源,去官⽹下载mysql的tar包
1.2 选择community
1.3 选择5.7对应的版本下载
2.上传tar包到服务器
/usr/local/
⼆.开始安装
3.卸载系统⾃带的Mariadb
[root@hdp265dnsnfs ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.s.x86_64
[root@hdp265dnsnfs ~]# rpm -e --nodeps mariadb-libs-5.5.s.x86_64 4.删除etc⽬录下的myf⽂件
[root@hdp265dnsnfs ~]# rm /etc/myf
rm: cannot remove ?etc/myf? No such file or directory
5.检查mysql是否存在
[root@hdp265dnsnfs ~]# rpm -qa | grep mysql
[root@hdp265dnsnfs ~]#
mysql下载starting the server6.检查mysql组和⽤户是否存在,如⽆创建
[root@hdp265dnsnfs ~]# cat /etc/group | grep mysql
[root@hdp265dnsnfs ~]#  cat /etc/passwd | grep mysql
7.创建mysql⽤户组
[root@hdp265dnsnfs ~]# groupadd mysql
8.创建⼀个⽤户名为mysql的⽤户并加⼊mysql⽤户组
[root@hdp265dnsnfs ~]# useradd -g mysql mysql
9.制定password 为111111
[root@hdp265dnsnfs ~]# 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.
10.准备解压安装/usr/local
root@hdp265dnsnfs local]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_
[root@hdp265dnsnfs local]# mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql57
#更改所属的组和⽤户
[root@hdp265dnsnfs local]# chown -R mysql mysql57/
[root@hdp265dnsnfs local]# chgrp -R mysql mysql57/
[root@hdp265dnsnfs local]# cd mysql57/
[root@hdp265dnsnfs mysql57]# mkdir data
[root@hdp265dnsnfs mysql57]# chown -R mysql:mysql data
11 在etc下新建配置⽂件myf,并在该⽂件内添加以下配置
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端⼝
port = 3306
# 设置mysql的安装⽬录
basedir=/usr/local/mysql57
# 设置mysql数据库的数据的存放⽬录
datadir=/usr/local/mysql57/data
# 允许最⼤连接数
max_connections=200
# 服务端使⽤的字符集默认为8⽐特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使⽤的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
12. 安装和初始化
[root@hdp265dnsnfs mysql57]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql57/ --datadir=/var/mysql57/data/
2017-04-17 17:40:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-04-17 17:40:05 [WARNING] The bootstrap log isn't empty:
2017-04-17 17:40:05 [WARNING] 2017-04-17T09:40:02.728710Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2017-04-17T09:40:02.729161Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-04-17T09:40:02.729167Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
[root@hdp265dnsnfs mysql57]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@hdp265dnsnfs mysql57]# chown 777 /etc/myf
[root@hdp265dnsnfs mysql57]# chmod +x /etc/init.d/mysqld
13.重启
[root@hdp265dnsnfs mysql57]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
14.设置开机启动
[root@hdp265dnsnfs mysql57]# chkconfig --level 35 mysqld on
[root@hdp265dnsnfs mysql57]# chkconfig --list mysqld
[root@hdp265dnsnfs mysql57]# chmod +x /etc/rc.d/init.d/mysqld
[root@hdp265dnsnfs mysql57]# chkconfig --add mysqld
[root@hdp265dnsnfs mysql57]# chkconfig --list mysqld
[root@hdp265dnsnfs mysql57]# service mysqld status
SUCCESS! MySQL running (4475)
15.设置环境变量etc/profile/
export PATH=$PATH:/var/mysql57/bin
[root@hdp265dnsnfs mysql57]# source /etc/profile
16. 获得初始密码
[root@hdp265dnsnfs bin]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-04-17 17:40:02
_pB*3VZl5T<6
17. 修改密码
[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.18
Copyright (c) 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('111111');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
18 .添加远程访问权限
在本机先使⽤root⽤户登录mysql: mysql -u root -p"youpassword" 进⾏授权操作:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
重载授权表:
FLUSH PRIVILEGES;
退出mysql数据库:
exit
19.重启⽣效
/bin/systemctl restart  mysql.service
[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
20. 为了在任何⽬录下可以登录mysql ln -s /usr/local/mysql57/bin/mysql  /usr/bin/mysql
三.开启外部访问数据库
21. 开放防⽕墙端⼝
firewall-cmd --list-all
22.开放3306端⼝
firewall-cmd --permanent --add-port=3306/tcp 23.查看3306端⼝是否开放
firewall-cmd --query-port=3306/tcp
24.次查看现在防⽕墙
firewall-cmd --list-all

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。