当前位置:网站首页>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 .
边栏推荐
- Hanging memory recursive dynamic programming (with example explanation POJ 1163)
- Linux环境安装mysql数据库详细教程(含卸载和密码重置过程)
- Major work title and requirements of engineering earthquake resistance in autumn 21 [standard answer]
- Hospital intelligent infusion management system source code hospital source code
- SISO decoder for repetition (supplementary Chapter 4)
- WR | effect of micro nano plastic pollution in Jufeng formation of West Lake University on microbial flora and nitrogen removal function of Constructed Wetland
- 懂机器学习如何入门量化交易?
- Golang learning notes - Basics
- Poj1028 web navigation
- 图像变换 torchvision.transforms 笔记
猜你喜欢

懂机器学习如何入门量化交易?

WinCC flexible 2008项目移植到博途WinCC的具体方法

Detailed explanation of iSCSI (IV) -- actual configuration of iSCSI server

30讲 线性代数第二讲 矩阵

Use Mysql to determine the day of the week

【C语言刷题——Leetcode10道简单题】

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

Hanging memory recursive dynamic programming (with example explanation POJ 1163)

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

dried food! Information diffusion prediction based on sequence hypergraph neural network
随机推荐
基于飞桨搭建的多模态学习工具包PaddleMM
Understand how to get started with machine learning to quantify transactions?
YOLOv3 Pytorch代码及原理分析(一):跑通代码
构建Web应用程序
Big work and requirements of economics in autumn 21 of Dagong [standard answer]
2022Redis7.0x版本持久化详细讲解
cocan yocto buildroot
Hanging memory recursive dynamic programming (with example explanation POJ 1163)
SISO decoder for SPC (supplementary Chapter 1)
Leetcode2027. 转换字符串的最少操作次数(可以,一次过)
[help] how can wechat official account articles be opened in an external browser to display the selected messages below?
Google proposed the super pre training model coca, and the accuracy of fine-tuning top-1 on Imagenet reached 91%! SOTA! On multiple downstream tasks
Off line operation of situation and policy (version) of Dayong in autumn 21 [standard answer]
Common - name of conference room
Summary 111111111111111111111
Flutter--Button浅谈
Merge multiple binary search trees
WR | 西湖大学鞠峰组微纳塑料污染对人工湿地菌群与脱氮功能的影响
Lecture 30 linear algebra Lecture 2 Matrix
Golang学习笔记—基础篇