zoukankan      html  css  js  c++  java
  • Mysql二进制安装5.6和5.7

    Mysql二进制安装

    Mysql二进制安装

    5.6版本

    #cmake
    #定制功能:存储引擎、字符集、压缩
    #定制安装位置、数据存放位置、文件位置(socket)
    
    #创建目录
    [root@db04 ~]# mkdir /server/tools -p
    
    #进入目录
    [root@db04 ~]# cd /server/tools
    
    #上传二进制mysql包
    [root@db04 tools]# rz
    
    #解压mysql包
    [root@db04 tools]# tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz 
    [root@db04 tools]# ll
    total 320864
    drwxr-xr-x 13 root root       191 Jul  8 20:27 mysql-5.6.40-linux-glibc2.12-x86_64
    -rw-r--r--  1 root root 328563044 Jul  7 22:22 mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
    
    #移动MySQL程序到安装目录下
    [root@db04 tools]# mv mysql-5.6.40-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.40
    
    #做软链接
    [root@db04 tools]# ln -s /usr/local/mysql-5.6.40 /usr/local/mysql
    
    #进入其他文件目录
    [root@db04 tools]# cd /usr/local/mysql/support-files/
    
    #拷贝配置文件
    [root@db04 support-files]# cp my-default.cnf /etc/my.cnf
    cp: overwrite ‘/etc/my.cnf’? y
    
    #拷贝启动脚本
    [root@db04 support-files]# cp mysql.server /etc/init.d/mysqld
    
    #安装初始化依赖包
    [root@db04 support-files]#  yum install -y libaio-devel ncurses-devel cmake 
    
    #下载模块
    [root@db04 scripts]# yum install -y autoconf
    
    #进入初始化目录
    [root@db04 support-files]# cd ../scripts/
    
    #创建mysql用户
    [root@db04 scripts]#  useradd mysql -s /sbin/nologin -M
    
    #初始化
    [root@db04 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    看到2个ok就是初始化完毕
    
    #加入开机自启
    [root@db04 mysql-5.6.36]# chkconfig mysqld on
    
    #启动MySQL
    [root@db04 scripts]# /etc/init.d/mysqld start
    
    #添加环境变量
    [root@db04 scripts]# vim /etc/profile.d/mysql.sh
    export PATH="/usr/local/mysql/bin:$PATH"
    
    #加载环境变量
    [root@db04 scripts]# source /etc/profile.d/mysql.sh
    
    #检查是否启动成功
    [root@db04 scripts]#  ps -ef|grep [m]ysql
    
    #停止运行
    [root@db04 scripts]# etc/init.d/mysqld stop
    
    #用systemctl启动
    [root@db04 scripts]#  vim /usr/lib/systemd/system/mysqld.service
    
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    LimitNOFILE = 5000
    [root@db04 scripts]# systemctl start mysqld
    
    #给MySQL的root用户设置密码
    [root@db04 scripts]# mysqladmin -uroot -p password '123'
    
    #连接MySQL
    [root@db04 ~]# mysql -uroot -p123
    
    #查看MySQL中所有用户
    mysql> select user,host from mysql.user;
    
    

    5.7版本

    #下载mysql5.7二进制包,解压到当前目录下
    
    [root@long tools]# tar -zxf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 
    
    
    #将解过的mysql5.7包移动到/usr/local/下并改名为mysql
    
    [root@long tools]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
    
    
    #切换到/usr/local/mysql下
    
    /usr/local/mysql
    
    
    #新增mysql用户,并禁止shell登陆
    
    [root@long mysql]# useradd -r -g mysql -s /sbin/nologin mysql
    
    #初始化mysql5.7数据库
    
    [root@long mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    
    2019-11-04T09:24:32.797330Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2019-11-04T09:24:32.797401Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
    2019-11-04T09:24:32.797405Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
    2019-11-04T09:24:34.017863Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2019-11-04T09:24:34.128559Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2019-11-04T09:24:34.191564Z 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: e9e9af58-fee4-11e9-8a3d-00163e305554.
    2019-11-04T09:24:34.193913Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2019-11-04T09:24:34.194355Z 1 [Note] A temporary password is generated for root@localhost: v?_yAzh2.NI>
    
    -----注意生成的临时密码 : v?_yAzh2.NI>
    
    [root@long mysql]# ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
    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'
    
    #继续执行
    ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
    
    复制配置文件并修改
    
    注意,如果./support-files/my-default.cnf 没有这个文件,可以到网上去收一下这个文件的大致内容。
    
    #复制主配置文件
    cp ./support-files/my-default.cnf /etc/my.cnf
    
    #修改 /etc/my.cnf 配置文件
    
    # vi /etc/my.cnf
    # These are commonly set, remove the # and set as required.
    basedir = /usr/local/mysql //指定程序路径
    datadir = /usr/local/mysql/data //指定数据存放路径
    port = 3306 //指定端口号
    # server_id = .....
    socket = /tmp/mysql.sock //指定sock文件
    复制启动文件并修改相关参数
    
    a.复制启动脚本文件到init.d下
    
    cp ./support-files/mysql.server /etc/init.d/mysqld
    b.修改启动脚本相关参数
    
    vim /etc/init.d/mysqld
    basedir=/usr/local/mysql //指定程序路径
    datadir=/usr/local/mysql/data //指定数据存放路径
    ​```
    
    #### #启动mysql服务,并查看服务启动状态
    
    
    [root@long mysql]# /etc/init.d/mysqld start 
    
    
    [root@long ~]# netstat -ntlp | grep 3306
    
    tcp6       0      0 :::3306                 :::*                    LISTEN      32660/mysqld    
    
    chkconfig --add mysqld //加入开机启动
    
    #重置密码
    
    a.使用初始化临时密码登陆
    
    
    [root@long mysql]# /usr/local/mysql/bin/mysql -uroot -p'v?_yAzh2.NI>'
    
    mysql: [Warning] Using a password on the command line interface can be insecure.
    
    Welcome to the MySQL monitor.  Commands end with ; or g.
    
    
    b.修改mysql登陆密码:123
    
    
    mysql> set password = password('123');
    
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
  • 相关阅读:
    PHP 标量类型与返回值类型声明
    如何使用 PHP 语言来编码和解码 JSON 对象
    mongodb的读写分离
    [FWT] UOJ #310. 【UNR #2】黎明前的巧克力
    drcom 不耍流氓
    drcom 不耍流氓
    Visual Studio 自定义项目模板
    Visual Studio 自定义项目模板
    Visual Studio 自定义项目模板
    【广告】win10 uwp 水印图床 含代码
  • 原文地址:https://www.cnblogs.com/longren/p/11155914.html
Copyright © 2011-2022 走看看