赞
踩
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服务器
- 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 然后输入默认的密码
- # 设置密码等级
- set global validate_password_length=4;
- set global validate_password_policy=0;
- # 修改默认密码,注意替换后面的密码
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '您的密码';
我们退出后发现密码已经设置完成
设置 root 账户远程登陆(此步骤如果不需要可以跳过),进入到 MySQL 命令行使用命令:
- use `mysql`;
- # 注意将密码替换掉
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '您的密码' WITH GRANT OPTION;
- FLUSH PRIVILEGES;
现在我们使用 show variables like 'character%';
命令查看字符集看到一些字符集默认还是拉丁文,我们需要将他们改成 UTF-8
:
我们修改 /etc/my.cnf
文件来修改这个配置,使用命令:
vim /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
- [client]
- default-character-set=utf8
-
- [mysql]
- default-character-set=utf8
-
- [mysqld]
- character-set-server=utf8
- #
- # 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
- 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
重点注意修改部分:
- [client]
- default-character-set=utf8
-
- [mysql]
- default-character-set=utf8
-
- [mysqld]
- character-set-server=utf8
使用命令 systemctl restart mysqld
重启MySQL服务器后再查看:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。