Set the command to change the root password, connect MySQL, MySQL, common

Source: Internet
Author: User

Set Change root password

First check to see if MySQL has started
ps aux |grep mysql

If it doesn't start, start MySQL first
/etc/init.d/mysqld start

Add the MySQL directory to the environment variable first
export PATH=$PATH:/usr/local/mysql/bin/

The command is then written to the configuration file and is permanently active.
vim /etc/profile

Add the following content to the file
export PATH=$PATH:/usr/local/mysql/bin/

Set MySQL password
mysqladmin -uroot password ‘windows1.1‘

Set Password to windows1.1

Change MySQL Password
mysqladmin -uroot -p‘windows1.1‘ password ‘windows1.2‘

What to do if you forget your MySQL password
Edit MySQL configuration file
vim /etc/my.cnf

Under [Masqld], add the following (indicating ignore authorization)
skip-grand

Need to reproduce the startup service after changing the configuration file to take effect
/etc/init.d/mysqld restart

Log in to MySQL after restarting the service, you can log in without a password
mysql -uroot

Switch to MySQL Library
use mysql;

You can then change the password here to windows1.3
update user set password=password(‘windows1.3‘) where user=‘root‘;

After you change the password, quit MySQL, and then delete the Skip-grand from the MY.CNF in the configuration file.
Then restart the MySQL service again to complete the password change

Connect to MySQL

Connect to native MySQL, u specify user name, p specify password
mysql -uroot -p123456

Connect remote mysql,h Specifies the IP of the remote machine, uppercase p specifies the port
mysql -uroot -p123456 -h192.168.71.133 -P3306

Use sock to connect, uppercase s only sock
mysql -uroot -p123456 -S/tmp/mysql.sock

Connect to MySQL for operation,-e followed by commands, typically used in shell scripts
mysql -uroot -p123456 -e “show databases”

Common commands for MySQL

Query Library
show databases;

Switch to the library, where the demo switches to the MySQL library below
use mysql;

View the tables in the library
show tables;

View the fields in the table, which shows the fields in the user table
desc user;

View the built-in statement, shown here to view the user table, uppercase G for vertical display
show create table user\G;

View Current User
select user();

View the database currently in use
select database();

Create a library, shown here to create a library named TESTDB1
create database db1;

Create a table, shown here to create a table named T1, the first field is called an ID, and is an integer with a maximum of 4. The second field is called Name, which is a character, and a maximum of 40
create table t1(ID int(4), Namechar(40));

View Current database version
select version();

View database Status
show status;

View each parameter
show variables; show variables like ‘max_connect%‘;

modifying parameters
set global max_connect_errors=1000;

View queue show Processlist; Show full processlist;
show processlist; show full processlist;

Set the command to change the root password, connect MySQL, MySQL, common

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.