MySQL5.7安装配置

Posted Questions张

tags:

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

1.解压及创建目录
[[email protected] local]# tar xzvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql

[[email protected] local]# mkdir mysql/arch mysql/data mysql/tmp

2.创建my.cnf(见文件)
[[email protected] local]# vi /etc/my.cnf

3.创建用户组及用户
[[email protected] local]# groupadd -g 101 dba
[[email protected] local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
[[email protected] local]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)

## 一般不需要设置mysqladmin的密码,直接从root或者LDAP用户sudo切换
#[[email protected] local]# passwd mysqladmin
Changing password for user mysqladmin.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.


## if user mysqladmin is existing,please execute the following command of usermod.
#[[email protected] local]# usermod -u 514 -g dba -G root -d /usr/local/mysql mysqladmin


4.copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量
[[email protected] local]# cp /etc/skel/.* /usr/local/mysql ###important


5.配置环境变量
[[email protected] local]# vi mysql/.bash_profile
# .bash_profile
# Get the aliases and functions

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs
export MYSQL_BASE=/usr/local/mysql
export PATH=${MYSQL_BASE}/bin:$PATH


unset USERNAME

#stty erase ^H
set umask to 022
umask 022
PS1=`uname -n`":"‘$USER‘":"‘$PWD‘":>"; export PS1

## end

6.赋权限和用户组,切换用户mysqladmin,安装
[[email protected] local]# chown mysqladmin:dba /etc/my.cnf
[[email protected] local]# chmod 640 /etc/my.cnf


[[email protected] local]# chown -R mysqladmin:dba /usr/local/mysql
[[email protected] local]# chmod -R 755 /usr/local/mysql


7.配置服务及开机自启动
[[email protected] local]# cd /usr/local/mysql
#将服务文件拷贝到init.d下,并重命名为mysql
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
#赋予可执行权限
[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysql
#删除服务
[[email protected] mysql]# chkconfig --del mysql
#添加服务
[[email protected] mysql]# chkconfig --add mysql
[[email protected] mysql]# chkconfig --level 345 mysql on

8.安装libaio及安装mysql的初始db
[[email protected] mysql]# yum -y install libaio
[[email protected] mysql]# sudo su - mysqladmin

hadoop39.jiuye:mysqladmin:/usr/local/mysql:> bin/mysqld
--defaults-file=/etc/my.cnf
--user=mysqladmin
--basedir=/usr/local/mysql/
--datadir=/usr/local/mysql/data/
--initialize

在初始化时如果加上 –initial-insecure,则会创建空密码的 [email protected] 账号,否则会创建带密码的 [email protected] 账号,密码直接写在 log-error 日志文件中
(在5.6版本中是放在 ~/.mysql_secret 文件里,更加隐蔽,不熟悉的话可能会无所适从)

9.查看临时密码
hadoop39.jiuye:mysqladmin:/usr/local/mysql/data:>cat hostname.err |grep password
2017-07-22T02:15:29.439671Z 1 [Note] A temporary password is generated for [email protected]: kFCqrXeh2y(0
hadoop39.jiuye:mysqladmin:/usr/local/mysql/data:>


10.启动
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

11.登录及修改用户密码
hadoop39.jiuye:mysqladmin:/usr/local/mysql/data:>mysql -uroot -p‘kFCqrXeh2y(0‘
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.11-log

Copyright (c) 2000, 2016, 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> alter user [email protected] identified by ‘syncdb123!‘;
Query OK, 0 rows affected (0.05 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘syncdb123!‘ ;
Query OK, 0 rows affected, 1 warning (0.02 sec)


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

mysql> exit;
Bye

12.重启
hadoop39.jiuye:mysqladmin:/usr/local/mysql:> service mysql restart

hadoop39.jiuye:mysqladmin:/usr/local/mysql/data:>mysql -uroot -psyncdb123!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.11-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

 













































































以上是关于MySQL5.7安装配置的主要内容,如果未能解决你的问题,请参考以下文章

Atlas mysql5.7安装配置

CentOS7下安装MySQL5.7安装与配置(YUM)

Mysql5.7.14安装配置

docker 安装配置mysql5.7.18

MySQL5.7安装与配置(YUM)

Windows下安装配置免安装MySQL5.7服务器