mysql settings to change the root password, mysql server connection, mysql common commands diagram

mysql settings to change the root password, mysql server connection, mysql common commands diagram

1. Set and change the root password

Check whether mysql is started. If not, run :/usr/local/mysql56/bin/mysql

ps aux |grep mysql 或netstat -tulnp |grep 3306

Run the mysql command, and the following will appear:

-bash: mysql: command not found

Just add mysql to the environment variables:

Temporarily add: 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 a password for the root user

mysql -uroot password 'new_password' or use the following method

How to change your password:

mysqladmin -uroot -p 'old_password' password 'new_password' or use the following method


How to change the password if you forget it:

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

Add sed -i '/3306/a\skip-grant' /etc/my.cnf

Restart: /etc/init.d/mysqld restart


Then, switch the database: use mysql;

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

This will change the password back.


To retest, change my.cnf back:


2. Connection to mysql

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


3. Common mysql commands

Check how many databases there are: show databases;

Use a library: use database_name;

Check how many tables there are: show tables;

View the fields in a table: desc table_name:

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

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

Check which library is currently used: select database();

View the current database version: select version();

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

View the current number of processes: show processlist; or show full processlist; #This is the most commonly used (i.e., view the operations being performed by the database)

Create a database: create create database db_name;

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



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

The first part is complete.

Summarize

The above is the editor's introduction to MySQL settings to change the root password, MySQL server connection, and illustrations of MySQL common commands. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to reset the root password in mysql8.0.12
  • Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0
  • Detailed explanation of the idea of ​​installing mysql8.0.11 and changing the root password and connecting navicat for mysql
  • Solution to MySql error code 1045 under Windows
  • Solution to MySQL root password error number 1045

<<:  Practical record of vue using echarts word cloud chart

>>:  Detailed explanation of the update command for software (library) under Linux

Recommend

Implementation of new issues of CSS3 selectors

Table of contents Basic Selector Extensions Attri...

Native JS implementation of loading progress bar

This article shares a dynamic loading progress ba...

MySQL 5.7.17 installation and configuration tutorial for Mac

1. Download MySQL Click on the official website d...

How to set up the use of Chinese input method in Ubuntu 18.04

In the latest version of Ubuntu, users no longer ...

JavaScript implements mouse control of free moving window

This article shares the specific code of JavaScri...

9 great JavaScript framework scripts for drawing charts on the web

9 great JavaScript framework scripts for drawing ...

Summary of the differences between global objects in nodejs and browsers

In Node.js, a .js file is a complete scope (modul...

The latest Linux installation process of tomcat8

Download https://tomcat.apache.org/download-80.cg...

Detailed explanation of MySQL precompilation function

This article shares the MySQL precompilation func...

Nginx stream configuration proxy (Nginx TCP/UDP load balancing)

Prelude We all know that nginx is an excellent re...