centos7 + mysql5.7 tar包解压安装

MySQL官网下载地址:https://dev.mysql.com/downloads/mysql/

 复制代码

~]# rpm -qa|-libs-.-~]# rpm -e --nodeps mariadb-libs-.-~]#  /etc/: cannot remove ?etc/my.cnf? No such ~]# rpm -qa | ~~]#  /etc/group | ~]#   /etc/ | ~~]# useradd -~]# /usr/local空间不足,所以我安装到/ -zxvf mysql-.-linux-glibc2.-x86_64. mysql-.-linux-glibc2.-x86_64/ -R mysql mysql57/ -R mysql mysql57/
[root@hdp265dnsnfs var]# cd mysql57/

[root@hdp265dnsnfs mysql57]# mkdir data

复制代码

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

复制代码

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

复制代码

安装和初始化

复制代码

[root@hdp265dnsnfs mysql57]# bin/mysql_install_db --user=mysql --basedir=/var/mysql57/ --datadir=/var/mysql57/data/2017-04-17 17:40:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2017-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 instead2017-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/my.cnf 
[root@hdp265dnsnfs mysql57]# chmod +x /etc/init.d/mysqld

复制代码

[root@hdp265dnsnfs mysql57]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! #设置开机启动

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

复制代码

etc/profile/

export PATH=$PATH:/var/mysql57/bin

[root@hdp265dnsnfs mysql57]# source /etc/profile

获得初始密码

[root@hdp265dnsnfs bin]# cat /root/.mysql_secret  
# Password set for user 'root@localhost' at 2017-04-17 17:40:02 _pB*3VZl5T<6

 

修改密码

复制代码

[root@hdp265dnsnfs bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5Server version: 5.7.18Copyright (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)

复制代码

 

添加远程访问权限

 

复制代码

mysql>-> update user set host= where user= row affected (  Changed:   Warnings: > +-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+ rows  set ( sec)


create user 'xxx'@'%' identified by '123';  这里 @‘%’ 表示在任何主机都可以登录

复制代码

 

重启生效

/bin/systemctl restart  mysql.service

[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart 
Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!

 

为了在任何目录下可以登录mysql

ln -s /var/mysql57/bin/mysql   /usr/bin/mysql


猜你喜欢

转载自blog.51cto.com/13293070/2306792