当前位置:Gxlcms > 数据库问题 > install mysql on centos7

install mysql on centos7

时间:2021-07-01 10:21:17 帮助过:7人阅读

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

[root@localhost ~]# rm /etc/my.cnf

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

2.检查mysql是否存在

[root@localhost ~]# rpm -qa | grep mysql

[root@localhost ~]#

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

[root@localhost ~]# cat /etc/group | grep mysql

[root@localhost ~]# cat /etc/passwd | grep mysql

 4.创建mysql用户组

[root@localhost ~]# groupadd mysql

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

[root@localhost ~]# useradd -g mysql mysql

#制定password 为123456

[root@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

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

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

 6.更改所属的组和用户

[root@localhost ~]# chown -R mysql mysql5.7/

[root@localhost ~]# chgrp -R mysql mysql5.7/

[root@localhost ~]# cd mysql5.7/
[root@localhost mysql5.7]# mkdir data
[root@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.安装和初始化

[root@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)

 

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

[root@localhost mysql5.7]# chown 777 /etc/my.cnf

[root@localhost mysql5.7]# chmod +x /etc/init.d/mysqld

 

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

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

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

 10.etc/profile/

[root@localhost ~]# vi /etc/profile

export PATH=$PATH:/var/mysql57/bin
[root@localhost ~]# source /etc/profile


11.获得初始密码

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

12.修改密码

[root@localhost ~]# 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)


重启生效

[root@localhost ~]# service mysqld restart\
> ;
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!

 

[root@localhost ~]# ln -s /usr/local/mysql5.7/bin/mysql /usr/bin/mysql

done.

 

install mysql on centos7

标签:response   sid   instead   数据库   pen   init.d   evel   用户   客户端   

人气教程排行