zoukankan      html  css  js  c++  java
  • Linux 通过.tar.gz 安装MySQL 【已觉悟】

    以下步骤(都是精髓,哈哈): 

    1、下载 ->

    https://downloads.mysql.com/archives/community/

    img

     

     wget  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

    2、移动并创建用户授权解压的文件夹 ->

    tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 
    
    mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
    
    cd /usr/local/mysql/
    
    mkdir data
    
    #创建mysql用户并将mysql文件夹赋给mysql用户
    
    groupadd mysql
    
    useradd -g mysql mysql
    
     
    
    chown -R mysql:mysql /usr/local/mysql/
    
    chown -R mysql /usr/local/mysql/
    
    chmod -R 755 /usr/local/mysql/
    
    yum install  libaio-devel.x86_64

     

    3、执行安装命令(获取临时密码) ->

    bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

     提取临时密码:

    2021-08-02T04:31:06.667033Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
    2021-08-02T04:31:07.442249Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-08-02T04:31:07.550975Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2021-08-02T04:31:07.628766Z 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: 74b825f8-f34a-11eb-89d0-000c29e6d702.
    2021-08-02T04:31:07.640638Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-08-02T04:31:07.642172Z 1 [Note] A temporary password is generated for root@localhost: XbmEmHM*w7U6

    注意:如果想重新生成,请删除根目录下的data目录下的全部文件,再重新初始化!!

    4、修改配置文件(/etc/my.conf) ->

    vim /etc/my.cnf

    [mysqld]
    datadir=/usr/local/mysql/data
    port=3306
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    symbolic-links=0
    max_connections=600
    innodb_file_per_table=1
    lower_case_table_names=1
    #skip-grant-tables

    5、创建启动脚本并设置开机自启并立即启动(不然无法登录) ->

    vim   /usr/lib/systemd/system/mysql.service       

    [Unit] 
    Description=MySQL Server
    After=network.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    Type=forking
    TimeoutSec=0
    PermissionsStartOnly=true
    ExecStart=/usr/local/mysql/support-files/mysql.server start
    ExecStop=/usr/local/mysql/support-files/mysql.server stop
    LimitNOFILE = 65535
    Restart=on-failure
    RestartSec=10
    RestartPreventExitStatus=1
    PrivateTmp=false

    chmod 777 /usr/lib/systemd/system/mysql.service     #设置权限

    systemctl daemon-reload             #重新加载一下

    systemctl enable mysql.service     #设置该服务为开机自启

    systemctl  is-enabled  mysql.service   #查看是否能开机自启,enabled代表是,disabled则不行!

    systemctl start mysql.service   #能否登录的关键点

    6、将mysql加入环境变量(哪个位置都可以操作mysql) ->

    vim /etc/profile
    
    追加:
    #mysql
    export PATH=$PATH:/usr/local/mysql/bin

     source   /etc/profile  #重新加载这个文件

    7、利用临时密码登录并修改密码+可远程登录 —>

    #注意:必须保证mysql已经启动了,本步骤报错有解决方法,博主就不能执行use mysql,报了一个错,请看本步骤最下面  

    mysql -uroot -p临时密码  #如果不行,可以先mysql -uroot -p回车再粘贴密码
    use mysql  
    
    update user set authentication_string=password("xxxxxx") where user="root"; #设置密码,如果报错,请看下面的解决方面
    # (5.7之前:mysql> UPDATE user SET Password = password ('XXXXX') WHERE User = 'root';)
    
    
    use mysql
    update user set host='%' where user = 'root'; #允许远程连接
    exit;
    systemctl restart mysql.service #需要重新启动,不然远程连接失败

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

    alter user 'root'@'localhost' identified by '你的密码';

    SET PASSWORD = PASSWORD('你的新密码') ;  

    8、退出并用新密码重新登录 END!

    mysql -uroot -p你的新密码

  • 相关阅读:
    三种常见的编码:ASCII码、UTF-8编码、Unicode编码等字符占领的字节数
    快学Scala习题解答—第十章 特质
    [LeedCode OJ]#63 Unique Paths II
    收集互联网博客
    Android 内存监测工具 DDMS --> Heap(转)
    (转载)测试工具monkey
    (转载)Git使用教程
    时间戳转换为时间字符串
    二维码相关知识点
    教你跳转到系统指定页面
  • 原文地址:https://www.cnblogs.com/zjazn/p/14868007.html
Copyright © 2011-2022 走看看