install mysql on centos7

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了install mysql on centos7相关的知识,希望对你有一定的参考价值。

[[email protected] ~]# wget -c https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
--2017-12-10 14:40:34--  https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.56.185.130
Connecting to cdn.mysql.com (cdn.mysql.com)|23.56.185.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 641127384 (611M) [application/x-tar-gz]

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

[[email protected] ~]# rm /etc/my.cnf

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

2.检查mysql是否存在

[[email protected] ~]# rpm -qa | grep mysql

[[email protected] ~]#

 3.检查mysql组和用户是否存在,如无创建

[[email protected]localhost ~]# cat /etc/group | grep mysql

[[email protected]localhost ~]# cat /etc/passwd | grep mysql

 4.创建mysql用户组

[[email protected]localhost ~]# groupadd mysql

#创建一个用户名为mysql的用户并加入mysql用户组

[[email protected]localhost ~]# useradd -g mysql mysql

#制定password 为123456

[[email protected]localhost ~]# 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.

 5.安装到/usr/local/mysql5.7

[[email protected]localhost ~]# tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

[[email protected]localhost ~]# mv mysql-5.7.20-linux-glibc2.12-x86_64/ /usr/local/mysql5.7

 6.更改所属的组和用户

[[email protected]localhost ~]# chown -R mysql mysql5.7/

[[email protected]localhost ~]# chgrp -R mysql mysql5.7/

[[email protected]localhost ~]# cd mysql5.7/
[[email protected]localhost mysql5.7]# mkdir data
[[email protected]localhost mysql5.7]# chown -R mysql:mysql data

 7.在etc下新建配置文件my.cnf,并在该文件内添加以下配置

 [mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/usr/local/mysql5.7
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql5.7/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M

 8.安装和初始化

[[email protected]localhost mysql5.7]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/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)

 

 [[email protected]localhost mysql5.7]# cp ./support-files/mysql.server /etc/init.d/mysqld

[[email protected]localhost mysql5.7]# chown 777 /etc/my.cnf

[[email protected]localhost mysql5.7]# chmod +x /etc/init.d/mysqld

 

[[email protected]localhost mysql5.7]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

9.设置开机启动
[[email protected]localhost mysql5.7]# chkconfig --level 35 mysqld on
[[email protected]localhost mysql5.7]# chkconfig --list mysqld

[[email protected]localhost mysql5.7]# chmod +x /etc/rc.d/init.d/mysqld
[[email protected]localhost mysql5.7]# chkconfig --add mysqld
[[email protected]localhost mysql5.7]# chkconfig --list mysqld
[[email protected]localhost mysql5.7]# service mysqld status
 SUCCESS! MySQL running (4475)

 10.etc/profile/

[[email protected] ~]# vi /etc/profile

export PATH=$PATH:/var/mysql57/bin
[[email protected] ~]# source /etc/profile


11.获得初始密码

[[email protected] ~]# cat /root/.mysql_secret
# Password set for user ‘[email protected]‘ at 2017-12-10 15:29:14
T*c*llRqeqE7

12.修改密码

[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20

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(‘123456‘);
Query OK, 0 rows affected, 1 warning (0.01 sec)

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

13.添加远程访问权限

mysql> update user set host=‘%‘ where user=‘root‘;
Query OK, 1 row affected (0.06 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> create user ‘xxx‘@‘%‘ identified by ‘123‘
    -> ;
Query OK, 0 rows affected (0.04 sec)


重启生效

[[email protected] ~]# service mysqld restart\
> ;
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!

 

[[email protected] ~]# ln -s /usr/local/mysql5.7/bin/mysql /usr/bin/mysql

done.

 



































































































以上是关于install mysql on centos7的主要内容,如果未能解决你的问题,请参考以下文章

Install and Config MySQL 8 on Ubuntu

Manual install on Windows 7 with Apache and MySQL

How to install MySQL on CentOS

How to Install Nginx with PHP + MySQL (LEMP) on Debian 9

mysql install on centos6.5

How to Install MySQL on CentOS 7