当前位置:网站首页>Detailed tutorial on installing MySQL database in Linux environment (including uninstallation and password reset process)
Detailed tutorial on installing MySQL database in Linux environment (including uninstallation and password reset process)
2022-06-11 19:43:00 【Kexiaonan】
This tutorial is for centos7/8,mysql 5.x
1、 uninstall mysql( important )
In the installation mysql Make sure you don't have... In your system before mysql, Even if you are a newly installed system or a newly purchased cloud service , You also need to check whether there is mysql Related documents , This is important !( Some images of Tencent cloud include by default mysql The file of ), If it already exists before installation mysql Related documents , Will lead to subsequent mysql Installation failed .
Completely delete mysql step :
(1) Use rpm Command to view installed packages
Enter the following command to check if mysql Software :
rpm -qa | grep mysql
If you find the relevant documents , for example 
Use rpm -e file name To delete the file , Take the above file as an example , Execute the following command :
rpm -e mysql57-community-release-el7-10.noarch
Reuse rpm -e Command to delete files , Until all files are completely deleted
(2) Use yum Uninstall the installed mysql
yum remove mysql mysql-server mysql-libs mysql-server
(3) Search for mysql file
The global search name contains mysql All files for
find / -name '*mysql*'
Delete all the search results mysql file , If not installed mysql, Usually search out /var/lib/* and /usr/share/* These two directories contain mysql file . Delete file command :
# With /var/lib/mysql For example
rm -rf /var/lib/mysql
Use rm -rf Command to delete all searched mysql file .
Linux Copy shortcut keys in :
ctrl + insert, Paste shortcut :shift + insertOr use the middle mouse button
Finally, check again :
# Check 1
rpm -qa|grep mysql
# Check 2
find / -name '*mysql*'
If any, continue to delete , Until it is deleted !
2、 download mysql The installation files
Linux It is recommended to use RPM Package to install mysql.
download :
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm install :
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server:
yum install -y mysql-server
If you don't have permission , You can execute the following command to set permissions (root The user does not need to execute ):
chown -R mysql:mysql /var/lib/mysql/
Start the service :
systemctl start mysqld.service
see mysql Running state :
service mysqld status

Check the initial password :
grep 'password' /var/log/mysqld.log

The initial password is marked in the red box , However, in some cases, the initial password cannot be queried , How to change the password will be said later .
Copy the initial password , Log in :
mysql -u root -p
After typing the command , Click enter , Will let you enter the password , Then input the initial password just now ( It is not visible when inputting the password ), Of course, paste is supported , You can copy the initial password after , Then paste . If there is no password , Just go back .
After logging in successfully, it will display :
View all databases :
Here we are ,mysql The database is installed .
3、 modify mysql password
In many cases , Need to change the initial password , But if you can't see the initial password in the previous steps , There is no way to log in to the database , Then you need to change the password . Let's take the inability to view the initial password as an example ( Or forget your login password ), Briefly introduce the password modification process .
(1) Set skip login password
open mysql Configuration file for :
vi /etc/my.cnf
Press... After opening the file a Key to enter edit mode , stay [mysqld] Add... Below the configuration skip-grant-tables, As shown in the figure below :
Then press esc key , Input :wq Save the file .
(2) restart mysql service
service mysqld restart
(3) Get into mysql
mysql -u root -p
Press enter after entering the above command , Will skip password verification , Direct access to mysql in .
(4) Change user login password
Get into mysql library :
use mysql

Change Password :
update user set password=password(' The password you set ') where User='root' and Host='localhost';
Be careful : Set up Host=‘localhost’ May cause the remote connection to fail !
Update cache :
flush privileges;
sign out mysql:
exit
(4) Restore profile
Re enter my.cnf Comment out the document skip-grant-tables, The effect is shown below 
Press esc Key to exit edit mode , Input :wq Save the file .
Restart again mysql service :
service mysqld restart
Then connect to the database , Enter your modified password to see if you can enter , If you can enter, it means that the password has been modified successfully , Otherwise, follow the steps again .
边栏推荐
- YOLOv3 Pytorch代码及原理分析(二):网络结构和 Loss 计算
- Leetcode 1992. Find all farm groups (yes, once)
- highcharts设置柱状图宽度、渐变、圆角、柱子上方数据
- [high precision] decimal integer addition
- Review of software testing technology
- Internet_ Business Analysis Overview
- In 2021, the global adult diaper revenue was about $11560million, which is expected to reach $15440million in 2028. From 2022 to 2028, the CAGR was 4.2%
- AHB_Bus_Matrix_3x3 设计
- APB2standard_ handshake_ Bridge design
- C#深拷贝
猜你喜欢

Multimodal learning toolkit paddlemm based on propeller

使用贝叶斯优化进行深度神经网络超参数优化

vs2010链接sql2008数据库时无法打开
![PIL pilot image processing [1] - installation and creation](/img/21/34856f53c08a5369b834b7ca2fb07b.jpg)
PIL pilot image processing [1] - installation and creation

AHB2Standard_handshake_bridge 设计

Pyramid test principle: 8 tips for writing unit tests

无监督图像分类《SCAN:Learning to Classify Images without》代码分析笔记(1):simclr

这些考研专业容易混淆,搞错就白考啦!

Tensorflow---TFRecord文件的创建与读取

Introduction to go language (V) -- branch statement
随机推荐
In 2021, the global adult diaper revenue was about $11560million, which is expected to reach $15440million in 2028. From 2022 to 2028, the CAGR was 4.2%
The latest test questions and answers for the eight major members (standard members) of Ningxia architecture in 2022
Review of software testing technology
司空见惯 - 会议室名称
模块八作业
Judge whether it is a balanced binary tree
CMU 15 - 445 cours de base de données Leçon 5 version texte - Pool tampon
Picture bed: picgo+ Tencent cloud +typera
SISO decoder for repetition (supplementary Chapter 4)
Golang learning notes - Basics
RTL arbiter design
Xmake help 2
Questions and requirements of marketing course design in autumn 21 of Dagong [standard answer]
Neural network and deep learning-2-simple example of machine learning pytorch
Golang学习笔记—基础篇
谷歌提出超强预训练模型CoCa,在ImageNet上微调Top-1准确率达91%!在多个下游任务上SOTA!...
Go语言入门(五)——分支语句
2022 the latest software testing classic summarized by major manufacturers. After reading it, I'm not afraid I won't get an offer
Find the maximum 3 same digits in the string
Calculate the number of 926 in the string to the power of 9260 of 926