MySQL5.7.18 for Linux7.2二进制安装详解

安装二进制的MySQL非常简单,因为只需要解压软件,然后初始化自己想要的数据库就可以了,具体的做法如下:

1、下载二进制软件包:
  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

2、添加MySQL用户和组:
  [root@localhost ~]# userdel mysql  (因为是新系统,所以就把现有的MySQL用户给删除了)
  [root@localhost ~]# groupadd mysql
  [root@localhost ~]# useradd -g mysql  mysql
  [root@localhost ~]# passwd mysql      (MySQL密码要设置的复杂一点,或者在创建用户的时候设置不让登陆系统)

3、创建安装MySQL目标,并解压软件到指定目录
  [root@localhost ~]# tar zxvf  mysql-5.7.18-linux-glibc2.5-x86_64 -C  /usr/local
  [root@localhost ~]# cd /usr/local
  [root@localhost ~]# mv mysql-5.7.18-linux-glibc2.5-x86_64    mysql

[root@localhost107 ~]# mkdir -p /opt/mysql/data/
[root@localhost107 ~]# chown -R mysql:mysql /opt/mysql

4、切换MySQL用户,并初始化数据库
  [root@localhost ~]# su - mysql
  [mysql@localhost ~]$ /usr/local/mysql/bin/mysqld  --initialize --user=mysql --basedir=/usr/local/mysql  --datadir=/opt/mysql/data &

    -----注意,初始化数据库会生成登录MySQL数据库的root密码,一定要记住,一会登录数据库要用

5、编辑my.cnf配置文件,启动数据库

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

[root@localhost ~]# chown mysql:mysql   /etc/my.cnf

 [root@localhost ~]# su - mysql
[mysql@localhost ~]$ vim  /etc/my.cnf    (该配置文件仅供参考)
[client]
socket=/usr/local/mysql/mysql.sock
[mysqld]
server_id=10
port=3306
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
plugin-dir=/usr/local/mysql/lib/plugin
pid-file=/usr/local/mysql/mysql.pid
log-error=/usr/local/mysql/mysql_error.log
log-bin=/usr/local/mysql/mysql_bin
#relay-log=/usr/local/mysql/data/relay_bin
#ssl-ca=/usr/local/mysql/data/ca.pem
#ssl-cert=/usr/local/mysql/data/server-cert.pem
#ssl-key=/usr/local/mysql/data/server-key.pem
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]

5:以跳过权限启动MySQL服务器:

[mysql@localhost ~]$/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql   --skip-grant-tables &


6:修改密码:

[mysql@localhost107 tmp]$ /usr/local/mysql/bin/mysql

mysql> select * from mysql.user;

mysql> set password for 'root'@'localhost' = password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

报错:是因为带--skip-grant-tables参数启动数据库,没有刷新权限

解决办法:

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


mysql> set password for 'root'@'localhost' = password('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)


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

密码修改成功!


7:停掉MySQL服务。不要带 --skip-grant-tables &参数

关闭服务器:

[mysql@localhost ~]$ su - mysql

[mysql@localhost107 tmp]$ /usr/local/mysql/bin/mysqladmin -uroot -p   shutdown

重新启动服务器;一定要去掉参数--skip-grant-tables

[mysql@localhost107 tmp]$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

查看进程是否存在:并检验参数是否正确:

[mysql@localhost107 tmp]$ ps -ef | grep mysql


8、进入数据库检查:

[mysql@localhost107 tmp]$ /usr/local/mysql/bin/mysql -uroot -p --socket=/usr/local/mysql/mysql3306.sock --port=3306
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log MySQL Community Server (GPL)


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='123456';  (因为刚才使用的密码是个默认的登录密码,所以我们要修改)
mysql>  flush privileges;

然后再重新登录MySQL即可,进行检查

mysql> s\
--------------
/mysql/mysql5718/bin/mysql  Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using  EditLine wrapper

Connection id:          7
Current database:
Current user:          root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:        5.7.18-log MySQL Community Server (GPL)
Protocol version:      10
Connection:            Localhost via UNIX socket
Server characterset:    utf8
Db    characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /mysql/data/mysql.sock
Uptime:                25 min 16 sec

Threads: 1  Questions: 19  Slow queries: 0  Opens: 110  Flush tables: 1  Open tables: 103  Queries per second avg: 0.012
--------------

mysql>

这样,二进制的MySQL就顺利安装完成了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值