centos7下mysql5.7 tar包安装

#卸载系统自带的mariadb
[root@VM_0_6_centos ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@VM_0_6_centos ~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

#删除etc目录下的my.cnf文件
[root@VM_0_6_centos ~]# rm /etc/my.cnf
rm: cannot remove ‘/etc/my.cnf’: No such file or directory

#检查mysql是否存在
[root@VM_0_6_centos ~]# rpm -qa | grep mysql
[root@VM_0_6_centos ~]#

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

#创建mysql用户组
[root@VM_0_6_centos ~]# groupadd mysql

#创建一个用户名为mysql的用户并加入mysql用户组
[root@VM_0_6_centos ~]# useradd -g mysql mysql

#制定password 为111111
[root@VM_0_6_centos ~]# 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的二进制文件
[root@VM_0_6_centos ~]# cd /usr/local
[root@VM_0_6_centos local]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@VM_0_6_centos local]# mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql

#更改所属的组和用户
[root@VM_0_6_centos local]# chown -R mysql mysql/
[root@VM_0_6_centos local]# chgrp -R mysql mysql/


[root@VM_0_6_centos mysql]# mkdir data
[root@VM_0_6_centos mysql]# chown -R mysql:mysql data

#在etc下新建配置文件my.cnf,并在该文件内添加以下配置
[root@VM_0_6_centos mysql]# vim /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@VM_0_6_centos mysql]# yum -y install numactl.x86_64
[root@VM_0_6_centos mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
[WARNING] The bootstrap log isn't empty:
[WARNING] 2019-07-07T02:51:50.085480Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead


[root@VM_0_6_centos mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@VM_0_6_centos mysql]# chown 777 /etc/my.cnf 
[root@VM_0_6_centos mysql]# chmod +x /etc/init.d/mysqld 
[root@VM_0_6_centos mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

#设置开机启动
[root@VM_0_6_centos mysql]# chkconfig --level 35 mysqld on
[root@VM_0_6_centos mysql]# chkconfig --list mysqld

[root@VM_0_6_centos mysql]# chmod +x /etc/rc.d/init.d/mysqld 
[root@VM_0_6_centos mysql]# chkconfig --add mysqld
[root@VM_0_6_centos mysql]# chkconfig --list mysqld


[root@VM_0_6_centos mysql]# service mysqld status 
 SUCCESS! MySQL running (10363)

#在etc/profile/配置环境变量
[root@VM_0_6_centos mysql]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@VM_0_6_centos mysql]# source /etc/profile

#获得初始密码
[root@VM_0_6_centos mysql]# cat /root/.mysql_secret 
# Password set for user 'root@localhost'
IZ9FSFvrh&Mz

#修改密码
[root@VM_0_6_centos mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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('your new password');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

#添加远程访问权限
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host ='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

#退出mysql
mysql> exit;
Bye
[root@VM_0_6_centos mysql]#

#重启生效
[root@VM_0_6_centos mysql]# /bin/systemctl restart mysql.service
[root@VM_0_6_centos mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

#在任何目录下可以登录mysql
[root@VM_0_6_centos mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值