当前位置:   article > 正文

Centos7:安装Mysql_centos安装mysql执行journalctl -xe报错mysql.service:contr

centos安装mysql执行journalctl -xe报错mysql.service:control process exited

wget \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-client-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-common-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-server-5.7.32-1.el7.x86_64.rpm

从官网下载软件包

  • 把他们下载到 CentOS 的 /usr/local/src 目录下,如图显示
    下载完成后的安装包

  • 然后安装这些安装包,注意有依赖,需要联网
    使用命令:

    yum install -y mysql-community-*-5.7.32-1.el7.x86_64.rpm
    

    看到这个画面表示安装成功
    MySQL安装成功

  • 开启服务器并初始化密码,使用的命令和命令详解:

    1. # 开启MySQL服务器
    2. systemctl start mysqld

 开启失败会提示Job for mysqld.service failed because the control process exited with error,请输入systemctl status mysqld.service 或者 journalctl -xn查看详细情况,

输入后发现我遇到的问题是Fatal error: mysql.user table is damaged. Please run mysql_upgrade.
解决办法:
[root@localhost ~]# rm -fr /var/lib/mysql

然后重启

也有其他同学遇到端口被占用的情况,那就kill掉再启动就行

 # 查看默认生成的密码
cat /var/log/mysqld.log | grep password

  • 使用该密码登录本地 MySQL 服务器,使用命令:

    然后输入以下命令修改默认密码:mysql -uroot -p 然后输入默认的密码

    1. # 设置密码等级
    2. set global validate_password_length=4;
    3. set global validate_password_policy=0;
    4. # 修改默认密码,注意替换后面的密码
    5. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '您的密码';

    我们退出后发现密码已经设置完成

  • 设置 root 账户远程登陆(此步骤如果不需要可以跳过),进入到 MySQL 命令行使用命令:

    1. use `mysql`;
    2. # 注意将密码替换掉
    3. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '您的密码' WITH GRANT OPTION;
    4. FLUSH PRIVILEGES;

  • 现在我们使用 show variables like 'character%'; 命令查看字符集看到一些字符集默认还是拉丁文,我们需要将他们改成 UTF-8拉丁文的编码字符集
    我们修改 /etc/my.cnf 文件来修改这个配置,使用命令:

    vim /etc/my.cnf
    

    修改之后:

    1. # For advice on how to change settings please see
    2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    3. [client]
    4. default-character-set=utf8
    5. [mysql]
    6. default-character-set=utf8
    7. [mysqld]
    8. character-set-server=utf8
    9. #
    10. # Remove leading # and set to the amount of RAM for the most important data
    11. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    12. # innodb_buffer_pool_size = 128M
    13. #
    14. # Remove leading # to turn on a very important data integrity option: logging
    15. # changes to the binary log between backups.
    16. # log_bin
    17. #
    18. # Remove leading # to set options mainly useful for reporting servers.
    19. # The server defaults are faster for transactions and fast SELECTs.
    20. # Adjust sizes as needed, experiment to find the optimal values.
    21. # join_buffer_size = 128M
    22. # sort_buffer_size = 2M
    23. # read_rnd_buffer_size = 2M
    24. datadir=/var/lib/mysql
    25. socket=/var/lib/mysql/mysql.sock
    26. # Disabling symbolic-links is recommended to prevent assorted security risks
    27. symbolic-links=0
    28. log-error=/var/log/mysqld.log
    29. pid-file=/var/run/mysqld/mysqld.pid

    重点注意修改部分:

    1. [client]
    2. default-character-set=utf8
    3. [mysql]
    4. default-character-set=utf8
    5. [mysqld]
    6. character-set-server=utf8

    使用命令 systemctl restart mysqld 重启MySQL服务器后再查看: 在这里插入图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号