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 root password to realize connection MYSQL, common commands

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following mainly brings you how to change the root password to achieve connection MYSQL, common commands, I hope these contents can bring you practical use, this is also my editor how to set and change the root password to achieve connection MYSQL, common commands of the main purpose of this article. All right, don't talk too much nonsense, let's just read the following.

Set to change the root password

The default mysqlroot user's password is empty, but this is not secure, so we need to configure a secure password

# mysql-uroot mysq command does not exist by default, because mysql is installed under / usr/local/mysql/bin, and there is no mysql command in the environment variable. You need to add the command to the environment variable # export PATH=$PATH:/usr/local/mysql/bin. If you want to take effect permanently, you need to put it in / etc/profile. Then execute # source / etc/profile#vim / etc/profile / / add the following export PATH=$PATH:/usr/local/mysql/bin#source / etc/profile# mysql-uroot-p 123456 / /-p to specify its password, and quit exit # mysqladmin-uroot-p '123456' password' 00000' / / change the password when we don't know the password of mysql Step to change password # vim / etc/my.cnf / / add skip-grant under [mysqld], ignore authorization skip-grant#/etc/init.d/mysqld restart / / restart mysql service # mysql-uroot / / login does not require a password. After logging in, you need to change a table. The password is stored in the mysql library # use mysql. / / switch to the mysql library # select * from user; / / View the user table, which stores the user's permissions, passwords, etc. # update user set password=password ('zenwenlinux') where user='root'; / / change the password finished mysql > update user set password=password (' 123456') where user='root' Query OK, 4 rows affected (0.02 sec) Rows matched: 4 Changed: 4 Warnings: "finally, delete the skip-grant in / etc/my.cnf, and then / etc/init.d/mysqld restart restart the mysql service. Mysql5.7root has a default password, which must be reset before mysql operation can be performed. Check the default password [root@localhost src] # cat / root/.mysql_secret# The random password set for the root userat Fri Jan 10 20:00:34 2014 (local time): aJqZsA2m the aJqZsA2m here is the generated root random password 2. Log in to mysql [root@localhost src] # mysql-uroot-pEnter password: enter the password aJqZsA2m above to log in. If you don't add the path of mysql to path, use the absolute path. Mysql-uroot-p can also be written as mysql-uroot-paJqZsA2m3. Change the password mysql > SET PASSWORD FOR 'root'@localhost = PASSWORD (' 123456'); Query OK, 0 rows affected (0.17 sec) so far, the password has been successfully modified. When the connection mysqlmysql service starts, it will listen not only to IP:Port, but also to a socket. The mysql we installed is listening in / tmp/mysql.sock. If the php is local, then php and mysql can communicate through socket, and if it is remote, it needs to be communicated through tcp/ip. # mysql-uroot-p123456 / / Log in to the local mysql. By default, use socket to connect to the remote mysql#mysql-uroot-p123456-h227.0.0.1-P3306 / /-h specify ip,-P designated port # mysql-uroot-p123456-S/tmp/mysql.sock / /-S specify its socket It is only suitable to connect the mysql operation command # mysql-uroot-p123456-e "show databases" / /-e to mysql common command query library show databases on this machine. Switch the library use mysql; to view the table in the library show tables; view the fields in the table desc tb_name; view the table creation statement show create table tb_name\ G; mysql > show create table db1\ G * * 1. Row * * Table: db1Create Table: CREATE TABLE `db1` (`id` int (4) DEFAULT NULL, `name` char (40) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec) to view the current user select user (); view the current database select databsase () Create library create database db1; create table use db1; create table T1 (`id` int (4), `name` char (40)); delete table drop T1; view current database version select version (); view database status show status; view parameters show variables; show variables like 'max_connect%'; modify parameters set global max_connect_errors=1000; need to change the configuration file # vim / etc/my.cnf if you want to take effect permanently

View queue show processlist; show full processlist

For the above about how to set and change the root password to achieve connection MYSQL, common commands, we do not find it very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

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