Home > System Tutorial > LINUX > MySQL basic installation: sharing from environment preparation to architecture, transactions, indexes and other aspects

MySQL basic installation: sharing from environment preparation to architecture, transactions, indexes and other aspects

PHPz
Release: 2024-07-11 13:40:05
Original
816 people have browsed it

MySQL 基础安装篇:从环境准备到架构、事务、索引等多方面分享

Preface

Compared with other small databases such as Oracle, SQL Server, etc., MySQL has its own shortcomings, but this has not reduced its popularity at all. For ordinary individual users and medium and large enterprises, the functions provided by MySQL are more than sufficient. However, because MySQL is an open source software, it can greatly reduce the total cost of ownership, so it is widely used in all walks of life. It is popular and widely used, so it is usually a must-ask knowledge point in written examinations, so in the next period of time, follow the editor to learn the relevant knowledge of MySQL! The editor will share mysql installation, architecture, transactions, indexing Linux mobile phones, locks, sub-databases and sub-tables, performance optimization and other aspects. A journey of a hundred miles begins with a single step. Tomorrow we will start with the basic installation of MySQL. Come and learn together!

Environmental planning and environmental testing

This step is mainly to detect whether mysql has been installed before in the current centos system. If it has been installed, you need to completely delete some mysql-related packages to prevent some incredible errors from occurring, you know

rpm -qa|grep mysql
Copy after login

linux下安装wget_使用yum安装wget_linux yum安装wget

rpm -e mysql-community-common-5.7.36-1.el7.x86_64
rpm -e mysql-community-client-5.7.36-1.el7.x86_64
rpm -e mysql-community-server-5.7.36-1.el7.x86_64
rpm -e mysql-community-libs-compat-5.7.36-1.el7.x86_64
rpm -e mysql-community-libs-5.7.36-1.el7.x86_64
Copy after login

find / -name '*mysql*'
Copy after login

# 以 /etc/my.cnf等为例
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql 
rm -rf /var/lib/mysql 
rm -rf /usr/lib64/mysql
Copy after login

(According to the above command, delete all mysql related files)

Start the installation and use yum to install

linux yum安装wget_linux下安装wget_使用yum安装wget

#下载yum源 
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm 
#安装yum源 
rpm -ivh mysql80-community-release-el7-3.noarch.rpm 
#使用此命令可以查看 MySQL Yum 存储库中的所有子存储库,并查看其中哪些子存储库已启用或禁用 
yum repolist all | grep mysql 
#关闭mysql8的下载源 
yum-config-manager --disable mysql80-community 
#开启mysql5.7下载源 
yum-config-manager --enable mysql57-community 
#安装mysql5.7 
yum install -y mysql-community-server
Copy after login

Configuration

vim /etc/my.cnf
Copy after login
Copy after login

The changes are as follows:

[mysqld] 
# MySQL设置大小写不敏感:默认:区分表名的大小写,不区分列名的大小写 
# 0:大小写敏感 1:大小写不敏感 
lower_case_table_names=1 
# 默认字符集 
character-set-server=utf8
# 设置时区
default-time_zone = '+8:00'
Copy after login

Startup

systemctl start mysqld
Copy after login

Set root user password

After installing mysql5.7, the initial password will no longer be empty by default. The initial password will generate a default password. The password will be output to the mysql log. The location of the log file is /var/log/mysqld.log

vim /var/log/mysqld.log
Copy after login

After executing the vim commandlinux yum to install wget, enter "/password", the location in the screenshot below is the initial password

使用yum安装wget_linux yum安装wget_linux下安装wget

#1.登录mysql 
[root@localhost ~]# mysql -uroot -p't)WMH;uUe9Jn' 
#mysql5.7以后对密码的强度是有要求的,必须是字母+数字+符号组成的,如果想设置简单密码例 如‘root’,需要做以下设置 
#2.设置密码长度最低位数 
mysql> set global validate_password_length=4; 
#3.设置密码强度级别 
mysql> set global validate_password_policy=0; 
#4.修改密码 
mysql> alter user 'root'@'localhost' identified by 'root';
Copy after login

Some general settings for password complexity are as follows:

Policy

TestsPerforme

0orLOW

Length

1orMEDIUM

numeric,lowercase/uppercase,andspecialcharacters

linux yum安装wget_使用yum安装wget_linux下安装wget

2orSTRONG

Length;numeric,lowercase/uppercase,andspecialcharacters

注意:默认是1,即MEDIUM,所以刚开始设置的密码必须符合厚度,且必须富含数字linux yum安装wget,大写或小写字母,特殊字符。

MySQL远程联接授权登陆mysql

## -u:指定数据库用户名 
## -p:指定数据库密码,
## 记住-u和登录密码之间没有空格
mysql -uroot -proot
Copy after login

授权

授权命令:

grant 权限 on 数据库对象 to 用户
Copy after login

示例:

## 授予root用户对所有数据库对象的全部操作权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Copy after login

说明:

关掉linux的防火墙

虽然以上我们的mysql安装步骤就早已结束了,防火墙的设置只是针对有内网访问mysql的需求,这儿看实际需求,须要的话就设置一下

systemctl stop firewalld(默认) 
systemctl disable firewalld.service(设置开启不启动)
Copy after login

忘掉密码怎样办

mysql密码是不是都是记住密码,长时间不输入密码,致使忘掉了,不晓得你是不是,总之小编常常忘掉,所以记录下忘掉密码后重置密码的方式

更改配置

vim /etc/my.cnf
Copy after login
Copy after login

更改内容如下:

## 在/etc/my.cnf添加如下内容即可
skip-grant-tables
Copy after login

说明:skip-grant-tables选项的意思是启动MySQL服务的时侯跳过权限表认证。启动后,联接到MySQL的root将不须要口令(危险)。此项设置很危险,生产环境中谨记勿使用!生产环境中谨记勿使用!生产环境中谨记勿使用!

重启mysql

systemctl restart mysqld.service
Copy after login
Copy after login

登陆mysql

## 使用root登录mysq
mysql -u root
## 切换到到mysql库
use mysql
## 更新root密码
update user set authentication_string=password('123456') where User='root';
Copy after login

更改配置

将/etc/f里的skip-grant-tables配置项删掉

重启mysql

systemctl restart mysqld.service
Copy after login
Copy after login

The password reset is completed, you can happily log in to mysql with the new password!

End

There are only so many MySQL installations shared this time. If you need to communicate and learn, you can follow the public account [Review the past and learn the new Java], learn from each other and make progress together

The above is the detailed content of MySQL basic installation: sharing from environment preparation to architecture, transactions, indexes and other aspects. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template