• 二进制格式安装MySQL


    二进制格式安装MySQL

    下载二进制格式的mysql软件包

    1. 下载二进制格式的 mysql 软件包
    [root@localhost ~]# cd /usr/src/
    [root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
    .......
    [root@localhost src]# ls 
    debug  kernels  mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
    
    1. 创建用户和组
    [root@localhost ~]# groupadd -r mysql
    [root@localhost ~]# useradd -M -r -s /sbin/nologin -g mysql mysql
    
    1. 解压软件至 /usr/local/
    [root@localhost src]# tar zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    [root@localhost src]# ls /usr/local/
    bin  etc  games  include  lib  lib64  libexec  mysql-5.7.31-linux-glibc2.12-x86_64  sbin  share  src
    
    #做个软连接,方便操作
    [root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql
    [root@localhost local]# ll
    total 0
    drwxr-xr-x. 2 root root    6 Nov  5  2016 bin
    drwxr-xr-x. 2 root root    6 Nov  5  2016 etc
    drwxr-xr-x. 2 root root    6 Nov  5  2016 games
    drwxr-xr-x. 2 root root    6 Nov  5  2016 include
    drwxr-xr-x. 2 root root    6 Nov  5  2016 lib
    drwxr-xr-x. 2 root root    6 Nov  5  2016 lib64
    drwxr-xr-x. 2 root root    6 Nov  5  2016 libexec
    lrwxrwxrwx. 1 root root   35 Jan  8 13:10 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
    drwxr-xr-x. 9 7161 31415 129 Jun  2  2020 mysql-5.7.31-linux-glibc2.12-x86_64
    drwxr-xr-x. 2 root root    6 Nov  5  2016 sbin
    drwxr-xr-x. 5 root root   49 Dec 24 13:10 share
    drwxr-xr-x. 2 root root    6 Nov  5  2016 src
    
    1. 修改目录 /usr/local/mysql 的属主属组
    [root@localhost local]# chown -R mysql.mysql /usr/local/mysql*
    [root@localhost local]# ll mysql
    lrwxrwxrwx. 1 mysql mysql 35 Jan  8 13:10 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
    
    1. 添加环境变量
    [root@localhost ~]# vim /etc/profile.d/mysql.sh
    [root@localhost ~]# cat /etc/profile.d/mysql.sh 
    export PATH=/usr/local/mysql/bin:$PATH
    [root@localhost ~]# source /etc/profile.d/mysql.sh
    [root@localhost ~]# echo $PATH
    /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
    1. 建立数据存放目录
    [root@localhost ~]# mkdir /opt/data
    [root@localhost ~]# chown -R mysql.mysql /opt/data/
    [root@localhost ~]# ll -d /opt/data/
    drwxr-xr-x. 2 mysql mysql 6 Jan  8 13:41 /opt/data/
    
    1. 初始化数据库
    [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data --basedir=/usr/local/mysql
    2021-01-08T05:50:23.963006Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-01-08T05:50:24.553478Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-01-08T05:50:24.657628Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2021-01-08T05:50:24.732822Z 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: 67142018-5175-11eb-b9fe-000c29decd5a.
    2021-01-08T05:50:24.735150Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-01-08T05:50:25.814369Z 0 [Warning] CA certificate ca.pem is self signed.
    2021-01-08T05:50:26.196255Z 1 [Note] A temporary password is generated for root@localhost: CkIqTt7arh+f          #注意:最后的'CkIqTt7arh+f'是登陆数据库的零时密码,这个是随机的,切记要牢记!
    [root@localhost ~]# echo 'CkIqTt7arh+f' > pass     #做个备份,以免忘记
    
    1. 修改配置文件(没有就创建一个)
    [root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak         #先做个备份
    [root@localhost ~]# vim /etc/my.cnf
    [root@localhost ~]# cat /etc/my.cnf
    [mysqld]
    datadir=/opt/data
    socket=/tmp/mysql.sock
    basedir=/usr/local/mysql
    port=3306
    pid-file=/opt/data/mysql.pid
    character-set-server=utf8
    log-error=/var/log/mysqld.log
    
    1. 配置服务启动脚本
    [root@localhost support-files]# pwd
    /usr/local/mysql/support-files
    [root@localhost support-files]# ls
    magic  mysqld_multi.server  mysql-log-rotate  mysql.server
    [root@localhost support-files]# cp -a mysql.server /etc/init.d/mysqld
    [root@localhost support-files]# vim /etc/init.d/mysqld 
    ........
    basedir=/usr/local/mysql          #修改这两行参数
    datadir=/opt/data
    ........
    
    1. 启动 mysql
    [root@localhost ~]# service mysqld start
    Starting MySQL. SUCCESS! 
    
    1. 设置开机自动启动
    [root@localhost ~]# chkconfig --list
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    [root@localhost ~]# chkconfig --add mysqld             #添加开机自动启动
    [root@localhost ~]# chkconfig --list
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    
    1. 修改密码
    [root@localhost ~]# mysql -uroot -p'CkIqTt7arh+f'
    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 3
    Server version: 5.7.31
    
    Copyright (c) 2000, 2020, 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('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    
  • 相关阅读:
    GridView怪问题,更新时读取不到编辑后的值
    又过了一周
    虚惊一场
    [Joomla] 利用configuration.php存储简单数据
    [Joomla] Phoca Gallery 2.7去版权的方法
    SL还能做什么?
    [Joomla] Joomla 1.5不支持PHP 5.3
    [ecshop] 库项目的添加过程
    [Joomla] 著名CMS系统Joomla的后台图文解说
    了解Joomla
  • 原文地址:https://www.cnblogs.com/itwangqiang/p/14252385.html
Copyright © 2020-2023  润新知