zoukankan      html  css  js  c++  java
  • Linux安装MySQL5.7

    Linux安装MySQL5.7

    操作系统信息

    # cat /etc/issue

    CentOS release 6.5 (Final)

    Kernel on an m

     

    # uname -a

    Linux mysql5-6 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

    上传文件至Linux服务器

    652M mysql-5.7.17-linux-glibc2.5-x86_64.tar

    解压mysql-5.7.17-linux-glibc2.5-x86_64.tar

    shell> tar -xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar

    652M mysql-5.7.17-linux-glibc2.5-x86_64.tar

    624M mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

    28M mysql-test-5.7.17-linux-glibc2.5-x86_64.tar.gz

    shell> mv mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz /usr/local

    卸载系统自带的mysql

    shell> rpm -qa|grep -i mysql

    可能会出现以下的一个或多个,没有更好,说明你的系统很干净,但是以防万一,不管怎样,下面的操作还是检查一变

    perl-DBD-MySQL-4.013-3.el6.x86_64

    mysql-libs-5.1.71-1.el6.x86_64

    qt-mysql-4.6.2-26.el6_4.x86_64

    mysql-5.1.71-1.el6.x86_64

    mysql-server-5.1.71-1.el6.x86_64

    如果出现了上面的一个或多个,也不用担心,使用卸载命令,有几个删几个

    卸载命令:rpm -ev {包名}

    会出现很多问题,最常见的就是卸载mysql-libs-5.1.71-1.el6.x86_64 会发现postfix-2:2.6.6-2.2.el6_1.x86_64被依赖,不用担心,用下面这个命令就OK啦

    rpm -ev mysql-libs-5.1.71-1.el6.x86_64 如果这句没用,则运行下面的这句

    rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

    重新检查

    shell> rpm -qa|grep -i mysql

    查找老版本mysql相关的安装目录命令:find / -name mysql

    若查找到相关目录使用命令:rm –rf {目录名}

    检查配置文件

    /etc/my.cnf or the /etc/mysql

    进入/etc/目录查看mysql的配置文件my.cnf是否存在,若存在则使用命令:rm –f my.cnf 进行删除。

    安装MySQL5.7

    挂载磁盘,安装依赖包

    shell> vi /etc/yum.repos.d/local.repo

    [base]

    name=local

    baseurl=file:///media

    gpgcheck=0

    enabled=1

    shell> mount /dev/sr0 /media

    shell> yum search libaio

    Loaded plugins: fastestmirror, refresh-packagekit, security

    Loading mirror speeds from cached hostfile

    base | 4.0 kB 00:00 ...

    ===================================================================================== N/S Matched: libaio ======================================================================================

    libaio.i686 : Linux-native asynchronous I/O access library

    libaio.x86_64 : Linux-native asynchronous I/O access library

    libaio-devel.i686 : Development files for Linux-native asynchronous I/O access

    libaio-devel.x86_64 : Development files for Linux-native asynchronous I/O access

     

    Name and summary matches only, use "search all" for everything.

     

    shell>

    shell> yum install libaio

    Loaded plugins: fastestmirror, refresh-packagekit, security

    Loading mirror speeds from cached hostfile

    Setting up Install Process

    Package libaio-0.3.107-10.el6.x86_64 already installed and latest version

    Nothing to do

     

    shell>

    ---------------------------------------------------------------------------------

    ########官方给的安装步骤-begin########

    shell> groupadd mysql

    shell> useradd -r -g mysql -s /bin/false mysql

    shell> cd /usr/local

    shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

    shell> ln -s full-path-to-mysql-VERSION-OS mysql

    shell> cd mysql

    shell> mkdir mysql-files

    shell> chmod 750 mysql-files

    shell> chown -R mysql .

    shell> chgrp -R mysql .

    shell> bin/mysql_install_db --user=mysql # MySQL 5.7.5

    shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up

    shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up

    shell> chown -R root .

    shell> chown -R mysql data mysql-files

    shell> bin/mysqld_safe --user=mysql &

    # Next command is optional

    shell> cp support-files/mysql.server /etc/init.d/mysql.server

    #This procedure assumes that you have root (administrator) access to your system. Alternatively, #you can prefix each command using the sudo (Linux) or pfexec (Solaris) command.

    ########官方给的安装步骤-end########

    ---------------------------------------------------------------------------------

    shell> groupadd mysql

    shell> useradd -r -g mysql -s /bin/false mysql

    解压

    shell> cd /usr/local

    shell> tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

    2.5G mysql-5.7.17-linux-glibc2.5-x86_64

    652M mysql-5.7.17-linux-glibc2.5-x86_64.tar

    624M mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

    28M mysql-test-5.7.17-linux-glibc2.5-x86_64.tar.gz

    shell> ln -s /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 mysql

    #加入环境变量

    shell> export PATH=$PATH:/usr/local/mysql/bin

    #or

    shell> vi ~/.bash_profile

    export PATH=$PATH:/usr/local/mysql/bin

    shell> source ~/.bash_profile

    创建目录并初始化

    shell> cd mysql

    shell> mkdir mysql-files

    shell> chmod 750 mysql-files

    shell> chown -R mysql .

    shell> chgrp -R mysql .

    shell> bin/mysqld --initialize --user=mysql

    #######mysqld --initialize-insecure自动生成无密码的root用户;

    #######mysqld --initialize是自动生成随机密码用户

    # bin/mysqld --initialize --user=mysql

    2017-07-28T08:51:56.297979Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

    2017-07-28T08:52:00.158925Z 0 [Warning] InnoDB: New log files created, LSN=45790

    2017-07-28T08:52:00.706047Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

    2017-07-28T08:52:00.782558Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0524601a-7372-11e7-81cb-000c294f09b9.

    2017-07-28T08:52:00.785616Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

    2017-07-28T08:52:00.787531Z 1 [Note] A temporary password is generated for root@localhost: iInaInXY09%c

    注意这里给的自动生成随机密码

    shell> bin/mysql_ssl_rsa_setup

    # bin/mysql_ssl_rsa_setup

    Generating a 2048 bit RSA private key

    .........+++

    ....................................................+++

    writing new private key to 'ca-key.pem'

    -----

    Generating a 2048 bit RSA private key

    ............+++

    .........+++

    writing new private key to 'server-key.pem'

    -----

    Generating a 2048 bit RSA private key

    ..................................................................................................+++

    ..........................................................+++

    writing new private key to 'client-key.pem'

    -----

    修改权限并启动数据库

    shell> chown -R root .

    shell> chown -R mysql data mysql-files

    shell> cp -a ./support-files/my-default.cnf /etc/my.cnf

    shell> cp -a support-files/mysql.server /etc/init.d/mysqld

    shell> chkconfig --add mysqld ###把mysql注册为开机启动的服务

    shell> chkconfig --list mysqld

    shell> bin/mysqld_safe --user=mysql&

    shell> /etc/init.d/mysqld restart

    # bin/mysqld_safe --user=mysql&

    [1] 4510

    [root@oracle11gr203db mysql]# 2017-07-28T08:54:16.946452Z mysqld_safe Logging to './data/oracle11gr203db.err'.

    Logging to './data/oracle11gr203db.err'.

    2017-07-28T08:54:17.055256Z mysqld_safe Starting mysqld daemon with databases from ./data

    2017-07-28T08:54:17.661300Z mysqld_safe mysqld from pid file ./data/oracle11gr203db.pid ended

     

    /etc/init.d/mysqld restart

     

     

    MySQL server PID file could not be found! [FAILED]

    Starting MySQL.Logging to '/usr/local/mysql/data/oracle11gr203db.err'.

    . [ OK ]

    [1]+ Done bin/mysqld_safe --user=mysql

     

     

    # service mysqld status

    MySQL running (5053) [ OK ]

     

    # ps -ef|grep mysql

    root 4961 1 0 17:08 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/oracle11gr203db.pid

    mysql 5053 4961 0 17:08 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/oracle11gr203db.err --pid-file=/usr/local/mysql/data/oracle11gr203db.pid

    root 5102 4194 0 17:10 pts/3 00:00:00 grep mysql

     

    # netstat -anpt

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1624/sshd

    tcp 0 52 172.168.183.148:22 172.168.183.1:58682 ESTABLISHED 3905/sshd

    tcp 0 0 :::22 :::* LISTEN 1624/sshd

    tcp 0 0 :::3306 :::* LISTEN 5053/mysqld

    #mysql服务的开启和关闭

    shell> /etc/init.d/mysqld start 或者 service mysqld start 或者 bin/mysqld_safe&

    shell> /etc/init.d/mysqld stop 或者 service mysqld stop 或者 bin/mysqladmin -uroot -p

    登录MySQL

    shell> mysql -uroot -piInaInXY09%c

    # mysql -uroot -piInaInXY09%c

    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 4

    Server version: 5.7.17

     

    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>

    mysql>

    mysql>

    mysql>

    mysql> show databases;

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    mysql>

    第一次登录需要重置密码

    设置密码,以下两种方式均可:

    1---mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Mysqlpassw0rd.');

    2---mysql> alter user 'root'@'localhost' identified by 'Mysqlpassw0rd.';

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123456';

    Query OK, 0 rows affected, 1 warning (0.00 sec)

     

    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root123456');

    Query OK, 0 rows affected, 1 warning (0.00 sec)

     

    mysql> use mysql

    mysql> select Host, User, authentication_string, plugin,password_expired from user where user='root' and host='root' or host='localhost';

    新安装的MySQL5.7, mysql数据库下已经没有password这个字段了,password字段改成了

    authentication_string

    所以更改语句替换为

    update MySQL.user set authentication_string=password('root') where user='root' ;

    忘记重改密码

    shell> mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

    # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

    [1] 3976

    [root@oracle11gr203db data]# 2017-07-28T08:09:08.347428Z mysqld_safe Logging to '/usr/local/mysql/data/oracle11gr203db.err'.

    2017-07-28T08:09:08.361474Z mysqld_safe Logging to '/usr/local/mysql/data/oracle11gr203db.err'.

    2017-07-28T08:09:08.469226Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

     

    # service mysqld status

    MySQL running (4087) [ OK ]

     

    # ps -ef|grep mysql

    root 3976 3955 0 16:09 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking

    mysql 4087 3976 1 16:09 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --skip-networking --log-error=/usr/local/mysql/data/oracle11gr203db.err --pid-file=/usr/local/mysql/data/oracle11gr203db.pid

    root 4130 3955 0 16:09 pts/0 00:00:00 grep mysql

    这种启动没有监听端口!

     

    shell> mysql -u root mysql

    新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root123456');

    mysql> flush privileges;

    mysql> use mysql

    mysql> select Host, User, authentication_string, plugin,password_expired from user where user='root' and host='root' or host='localhost';

    mysql 正在使用的 my.cnf 配置文件在哪个位置

    shell> mysql --help | grep my.cnf

    # mysql --help | grep my.cnf

    order of preference, my.cnf, $MYSQL_TCP_PORT,

    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

     

     

     

    # ll /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

    ls: cannot access /etc/my.cnf: No such file or directory

    ls: cannot access /etc/mysql/my.cnf: No such file or directory

    ls: cannot access /usr/local/mysql/etc/my.cnf: No such file or directory

    ls: cannot access /root/.my.cnf: No such file or directory

    我第一次安装好MySQL 5.7.17 时并没用创建/etc/my.cnf

    # cp -a ./support-files/my-default.cnf /etc/my.cnf

    # ll /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

    ls: cannot access /etc/mysql/my.cnf: No such file or directory

    ls: cannot access /usr/local/mysql/etc/my.cnf: No such file or directory

    ls: cannot access /root/.my.cnf: No such file or directory

    -rw-r--r-- 1 root mysql 1126 Nov 28 2016 /etc/my.cnf

    将/etc/my.cnf移动到/usr/local/mysql/

    shell> mv /etc/my.cnf /usr/local/mysql/

    修改数据库监听端口

    已将my.cnf移动到/usr/local/mysql/

    修改改配置文件,

    shell>vi /usr/local/mysql/my.cnf

    port = 3399 ##修改port参数

    重启数据库

    shell> service mysqld restart

    # service mysqld restart

    Shutting down MySQL.. [ OK ]

    Starting MySQL.. [ OK ]

    检查端口

    shell> netstat -anpt

    # netstat -anpt

    Active Internet connections (servers and established)

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1624/sshd

    tcp 0 0 172.168.183.148:22 172.168.183.1:58682 ESTABLISHED 3905/sshd

    tcp 0 0 :::22 :::* LISTEN 1624/sshd

    tcp 0 0 :::3399 :::* LISTEN 5498/mysqld

    参考文档

    linux mysql5.7.17安装教程

    https://jingyan.baidu.com/article/5553fa82a9858365a23934e1.html

    Mysql5.7Linux安装详细步骤

    http://www.2cto.com/database/201701/584468.html

    linux下mysql安装

    http://blog.csdn.net/bao19901210/article/details/51917641

    在Linux系统上卸载自带的mysql插件

    http://blog.csdn.net/qq_16066381/article/details/56300558

    转载于:https://www.cnblogs.com/hw-1015/p/7274998.html

  • 相关阅读:
    Win8系统 Python安装
    一些安卓开源框架整理
    Android 媒体键监听以及模拟媒体键盘的实现 demo
    android View 自动 GONE 问题
    Android 定时器TimerTask 简单使用
    关于Android studio 相对 eclipse 优点
    Java序列化与反序列化
    android shape的使用 边框
    Android Studio 修改 包名 package name
    Android WebView Long Press长按保存图片到手机
  • 原文地址:https://www.cnblogs.com/twodog/p/12139724.html
Copyright © 2011-2022 走看看