Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set and change the root password in mysql

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to set and change the root password in mysql, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Set and change the root password

Check whether mysql is started or not, and run it if not: / usr/local/mysql56/bin/mysql

Ps aux | grep mysql or netstat-tulnp | grep 3306

Run the mysql command and you will see:

-bash: mysql: command not found

Just add mysql to the environment variable:

Temporary addition: PAHT=$PATH:/usr/local/mysql56/bin

Permanently add: echo "export PATH=$PATH:/usr/local/mysql56/bin" > > / etc/profile

Then run soucre / etc/profile or. / etc/profile

Setting the mysql password, setting the password for root users

Mysql-uroot password' new_password' or in the following way

How to change the password:

Mysqladmin-uroot-p 'old_password' password' new_password' or in the following way

Forgot how to change the password:

First, you have to modify the configuration file: vim / etc/my.cnf

Add skip-grant under the [mysqld] module, and then restart the mysql service: sed-I'/ 3306 skip-grant' / etc/my.cnf

Restart: / etc/init.d/mysqld restart

Then, switch the database: use mysql

Then, change the root password in the database: update user set password=password ('new_password') where user='root'

So I changed the password back.

If you retest, change the my.cnf back:

2. The connection of mysql

Mysql-uroot-p'password'mysql-h227.0.0.1-uroot-p'password'mysql-S/tmp/mysql.sock-uroot-p'password'mysql-uroot-p-e "show databases"

3. Mysql common commands

Query how many libraries there are: show databases

Use a library: use database_name

Check how many tables there are: show tables

Check the fields in a table: desc table_name:

View the command entered when a table was created: show create table table_name\ G

Check which users are currently logged in: select user ()

Check which library is currently in use: select database ()

View the current database version: select version ()

View the various parameters that can be defined in the configuration file: show variables

Check the current number of processes: show processlist; or show full processlist; # this is the most used (that is, to see what the database is doing)

Create a database: create database db_name

Create a table: create table table_name ('name' types (length),' name' type (length),.)

Create a table: create table table_test (id int (10), name char (32), sex int (4))

The above content is how to set and change the root password in mysql. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report