• Mysql Liunx下安装指南


    1.检查是否安装了数据了

     ps ajx |grep mariadb
    
    • 1

    解决方案:

    # 第一步:
    # 停止服务即可
    systemctl stop mysqld
    
    #第二步:
    #列出所有被安装的rpm package
    ps axj |grep mariadb
    rpm -qa | grep mariadb 
    rpm -qa | grep mysql
    
    #第三步:
    #卸载显示出来的mariadb/mysql安装包
    sudo yum remove mariadb
    sudo yum remove mysql
    
    #第四步:
    #删除残留的文件,防止安装时的一些问题
    备份/etc/my.cnf,备份/var/lib/mysql数据(如果有重要的文件)
    cp -rf /etc/my.cnf /etc/my_backup.cnf
    cp -rf /var/lib/mysql /var/lib/mysql_backup
    rm -rf /var/lib/mysql (不删除,后续不会安装的)
    rm -rf /etc/my.cnf 
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    2. 正式安装

    2.1 安装MySQL的yum源

    第一步:获取mysql官方yum源 http://repo.mysql.com/

    # 一定要看下面的文字!如果后面自己安装不成功,就看看这个
    # 注意:最好安装和自己系统一致的mysql版本,否则可能会存在软件兼容性问题
    # 查看自己的系统版本
    # [root@VM-0-2-centos ~]# cat /etc/redhat-release
    # CentOS Linux release 7.5.2003 (Core)
    
    • 1
    • 2
    • 3
    • 4
    • 5

    可以进入 http://repo.mysql.com/, 找一下和自己版本一致的资源, 注意更换下面的wget 链接

    mysql80表示mysql 8.0版本 , mysql57 表示 5.7版本 ,尽量选择5.7以上的,因为支持的东西比较多

    我的服务器是centos7.5版本 对应 el7-5 ,  我选择mysql8.0的版本 对应 mysql80
    wget http://repo.mysql.com/mysql80-community-release-el7-5.noarch.rpm
    
    • 1
    • 2

    第二步检查是否已经安装yum源包

    ls 
    ## mysql80-community-release-el7-5.noarch.rpm
    
    • 1
    • 2

    第三步:安装yum源

    注意: rpm包可能不一样,因此应该安装自己对应的rpm包

    # 删除安装的yum源,防止已安装了其他版本的,删除后下面重装
    rpm -e mysql-community-release 
    # 重装 
    rpm -Uvh mysql80-community-release-el7-5.noarch.rpm
    
    • 1
    • 2
    • 3
    • 4

    第四步:对比前后yum源

    ls /etc/yum.repos.d/ -al
    
    • 1

    第五步:检查是否能运行yum

    #在看看能不能正常工作
    [whb@VM-0-3-centos 9.9]$ yum list |grep mysql
    
    • 1
    • 2

    第五步:安装mysql服务

    sudo yum install -y mysql-community-server
    
    • 1

    注意:
    这里可能会有警告,因此我们需要忽略警告。

    第六步:查看是否应该有MySQL的配置文件了(验证安装完)

    #查看配置文件
    [whb@VM-0-3-centos 9.9]$ ls /etc/my.cnf
    /etc/my.cnf
    [whb@VM-0-3-centos 9.9]$ sudo ls /var/lib/mysql
    ....
    
    • 1
    • 2
    • 3
    • 4
    • 5

    第七步:启动服务

    [whb@VM-0-3-centos 9.9]$ systemctl start mysqld.service
    ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
    Authentication is required to manage system services or units.
    Authenticating as: root
    Password:
    ==== AUTHENTICATION COMPLETE ===
    
    [whb@VM-0-3-centos 9.9]$ sudo ls -al /var/lib/mysql
    total 122956
    ……
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    第八步:设置不进行密码校验了

    a、大部分情况,是有默认密码或者不需要密码就能登录mysql的,但是偶尔会有例外

    1.修改MySQL的登录设置: 
    # vim /etc/my.cnf 
    
    2.在[mysqld]的段中加上一句:skip-grant-tables 
    
    例如: 
    
    [mysqld] 
    
    datadir=/var/lib/mysql 
    
    socket=/var/lib/mysql/mysql.sock 
    
    skip-name-resolve 
    
    skip-grant-tables 
    
    保存并且退出vi。 
    
    3.重新启动mysqld 
    
    systemctl restart mysqld
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    第九步:登录mysql修改密码

    #获取临时root密码
    [whb@VM-0-3-centos 9.9]$ sudo grep 'temporary password' /var/log/mysqld.log
    2021-04-12T03:23:46.153263Z 1 [Note] A temporary password is generated for root@localhost:
    yLMalT:v+5l*
    #使用临时密码登录
    [whb@VM-0-3-centos 9.9]$ mysql -uroot -p
    Enter password:
    #判断修改密码时候新密码是否符合当前的策略,不满足报错,不让修改,关闭它
    #安全强度,默认为中,即1,要求必须包含 数字、符号、大小写字母,长度至少为8位
    mysql> set global validate_password_policy=0;
    Query OK, 0 rows affected (0.00 sec)
    #密码最小长度
    mysql> set global validate_password_length=1;
    Query OK, 0 rows affected (0.00 sec)
    #修改本地登录密码,暂不授权远程登录
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer@wu.888';
    Query OK, 0 rows affected (0.00 sec)
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3. 后期mysql的配置

    https://www.cnblogs.com/my-global/articles/12887153.html

    #配置一下my.conf,主要是数据库客户端和服务器的编码格式
    [whb@VM-0-3-centos 9.9]$ cat /etc/my.cnf
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    [mysql]
    #default-character-set=utf8 ,暂不设置,mysql有bug,汉字不回显
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    port=3306
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    character-set-server=utf8
    default-storage-engine=innodb
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    mysql 已经配置了客户端服务器utf8编码,但是无法输入中文
    确保您在终端命令行中可以输入中文
    [whb@VM-0-3-centos ~]$ env |grep LANG
    LANG=en_US.utf8
    
    • 1
    • 2
    • 3
    • 4
  • 相关阅读:
    前端开发新趋势:Web3、区块链与虚拟现实
    【前端面试问题总结】2022.9.18
    Spring Data MongoDB SpEL表达式注入漏洞(CVE-2022-22980)分析与利用
    移动端1px边框的问题
    7-3 LVS+Keepalived集群叙述与部署
    985、211 毕业一年,面试八家大厂,四面拿美团 offer(Java 后端)
    mysql 查询优化 、索引失效
    UNIAPP实战项目笔记28 商品分享功能点分享按钮分享到微信好友
    发布版本自动化记录版本功能方法
    基于yolov7与arduino的眼睛跟随模块
  • 原文地址:https://blog.csdn.net/weixin_58004346/article/details/127801078