zoukankan      html  css  js  c++  java
  • Linux 安装mysql总结

    第一步:查询服务器残留mysql数据并删除

    rpm -qa |grep -i mysql
    find / -name mysql
    

    第二步:mysql安装包准备

    mysql官网下载地址:https://downloads.mysql.com/
    

    第三步:将mysql安装包上传到服务器

    往服务器上上传的工具很多,至于方法过于简单这里就不再赘述
    

    第四步:解压

    tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
    

    第五步:cp或mv到/usr/local/目录下,并命名为mysql

    注意:这里不建议使用拷贝(cp),因为文件大的话就会很慢

     mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql
    

    第六步:创建mysql用户组和用户

    groupadd mysql
    useradd -r -g mysql mysql
    

    第七步:创建mysql配置存放目录data

    cd /usr/local/mysql
    mkdir data
    

    第八步:为mysql目录修改用户权限

    chown -R mysql:mysql /usr/local/mysql/
    

    第九步:将mysql初始化,并记录初始密码(Bo39?ed2h*W1)

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

    如果出现以下错误:

    ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    
    出现该问题首先检查该链接库文件有没有安装使用命令进行核查
    #rpm -qa|grep libaio   
    运行该命令后发现系统中无该链接库文件
    使用命令,yum install  libaio-devel.x86_64
    安装成功后,继续运行数据库的初始化命令,提示成功。
    

    初始化成功后会出现以下:

    2021-01-30T03:51:20.337410Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-01-30T03:51:21.458335Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-01-30T03:51:21.659739Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2021-01-30T03:51:21.722351Z 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: 6a99bae9-62ae-11eb-8966-00163e175cc4.
    2021-01-30T03:51:21.724337Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-01-30T03:51:22.941639Z 0 [Warning] CA certificate ca.pem is self signed.
    2021-01-30T03:51:22.977097Z 1 [Note] A temporary password is generated for root@localhost: Bo39?ed2h*W1
    

    第十步:配置mysql(my.cnf)

    vim /etc/my.cnf
    [mysqld]
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    #skip-grant-tables
    port = 3306
    pid-file = /usr/local/mysql/data/mysql.pid
    socket = /usr/local/mysql/data/mysql.sock
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    default_authentication_plugin = mysql_native_password
    

    第十一步:加入开机自启

    cd /usr/local/mysql
    cp support-files/mysql.server /etc/init.d/mysql
    chmod  +x /etc/init.d/mysql   //添加可执行权限
    chkconfig --add mysql  // 添加开机自启
    chkconfig --list  //查看自启是否添加成功
    

    第十二步:配置环境变量

    vim /etc/profile
    export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
    source /etc/profile
    

    第十三步:启动mysql

    systemctl restart mysql
    

    第十四步:登录mysql

    ##初始化密码
    mysql -u root -pBo39?ed2h*W1 
    

    会出现以下错误:

    ERROR 2002 (HY000): Can’t connect to local MySQL
    server through socket ‘/tmp/mysql.sock’ (2)
    

    这个错误说是要改一下/tmp/mysql.sock目录

    vim /etc/my.cnf
    socket = /tmp/mysql.sock
    ##再重启服务
    systemctl restart mysql 
    

    再次登录:(mysql -u root -pBo39?ed2h*W1)

    修改密码

    ##关闭检测
    set global validate_password_policy=0; 
    ##修改密码长度最低6位,默认8位。
    set global validate_password_length=6;
    ##修改密码
    1.alter user 'root'@'localhost' identified with mysql_native_password by '123456';
    2.set password for root@localhost= password(‘123456’);
    ##刷新权限信息
    3.flush privileges;
    

    古今成大事者,不唯有超世之才,必有坚韧不拔之志!
  • 相关阅读:
    Hibernate学习笔记1.2(Annotation版本的Helloworld)
    Hibernate学习笔记1.1(简单插入数据)
    Java 分页与原理(上)
    触发器实例讲解
    URLRewrite 实现方法详解
    一个数组:1,1,2,3,5,8,13,21...+m,求第30位数是多少?用递归实现;(常考!!!)
    面向对象
    ajax 判断账户密码 调取数据模糊查询 时钟
    asp.net 类,接口
    asp.net get图
  • 原文地址:https://www.cnblogs.com/songwp/p/14348771.html
Copyright © 2011-2022 走看看