【MySQL】MySQL 在 Centos 7环境安装
目录
- 1. 卸载不要的环境
- 2. 检查系统安装包
- 3. 卸载这些默认安装包
- 4. 安装mysql
- 5. 启动服务
- 6. 查看启动服务
- 7. 登陆
- 8. 配置密码
- 9. 配置my.cnf
1. 卸载不要的环境
[xl@VM-0-3-centos ~]$ ps ajx |grep mariadb # 先检查是否有mariadb存在
...
[xl@VM-0-3-centos ~]$ ps axj |grep mariadb # 停⽌完成
2. 检查系统安装包
[xl@VM-0-3-centos ~]$ rpm -qa | grep mariadb
or
[xl@VM-0-3-centos ~]$ rpm -qa | grep mysql
# 下⾯是打印出来的mysql的样例,
[root@bite-alicloud mysql]# rpm -qa | grep mysql
mysql-community-common-5.7.41-1.el7.x86_64
mysql-community-server-5.7.41-1.el7.x86_64
mysql57-community-release-el7-11.noarch
mysql-community-client-5.7.41-1.el7.x86_64
mysql-community-libs-5.7.41-1.el7.x86_64
3. 卸载这些默认安装包
[xl@VM-0-3-centos ~]$ rpm -qa | grep mysql | xargs yum remove
or
[xl@VM-0-3-centos ~]$ rpm -qa | grep mariadb | xargs yum -y remove
4. 安装mysql
一键安装:(安装在新建的xl用户下的mysql文件夹里)
curl -sLf https://gitee.com/lpsdz-ybhdsg-jk/some-convenient-scripts/raw/master/mysql_install.sh -o /tmp/mysql_install.sh && bash /tmp/mysql_install.sh
5. 启动服务
[xl@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 ===
6. 查看启动服务
[xl@VM-0-3-centos 9.9]$ ps axj |grep mysqld
1 23183 23182 23182 ? -1 Sl 27 0:00 /usr/sbin/mysqld --
daemonize --pid-file=/var/run/mysqld/mysqld.pid
13134 23243 23242 13134 pts/0 23242 S+ 1005 0:00 grep --color=auto
mysqld
7. 登陆
[root@bite-alicloud mysql]# vim /etc/my.cnf # 打开mysql配置⽂件
在[mysqld]最后⼀栏配置(不知道是什么,就放在配置⽂件最后) 加⼊: skip-grant-tables 选项,
并保存退出
[root@bite-alicloud mysql]# systemctl restart mysqld # 重启mysql服务
# 登陆成功
[root@bite-alicloud mysql]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
8. 配置密码
#使⽤临时密码登录
[xl@VM-0-3-centos 9.9]$ mysql -uroot -p
Enter password:
9. 配置my.cnf
#配置⼀下my.conf,主要是数据库客⼾端和服务器的编码格式
[xl@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 //重点加入
# 配置完毕,重启mysql即可