Set change root password to connect MySQL mysql common commands

Source: Internet
Author: User

First, set the change root password

#/etc/init.d/mysqld start
#ps aux |grep MySQL
#mysql-uroot//hint-bash:mysql: Command not found
#ls/USR/LOCAL/MYSQL/BIN/MYSL//mysql Actual boot path
#echo $PATH//view PATH environment variable
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#export path= $PATH:/usr/local/mysql/bin/
#vi/etc/profile//Let the variable take effect permanently, export path= $PATH:/usr/local/mysql/bin/This command is placed in the last line of the configuration file
#source/etc/profile
#mysql-uroot-p//Specify user to specify password for root,-p, default password is empty
#mysqladmin-uroot password ' 123456 '//to root set password for 123456
#mysqladmin-uroot-p ' 123456 ' password ' 654321 '//change the root password to 654321 (know the original root password)

If you do not know the original root password, modify the root password;
Modifying a configuration file
#vi/etc/my.cnf
Add a row below [mysqld]
Skip Grant//Ignore authorization
#/etc/init.d/mysqld Restart//modified configuration restart MySQL
Login
#mysql-uroot//Verify that you can log in to MySQL without a password
mysql > Use MySQL; Switch to MySQL Library
MySQL > select * from User; View the user table for the account, password, and authorization
mysql > select password from user; Query password
MySQL > Update user set Password=password (' Aminglinux ') where user= ' root '; Change Password to Aminglinux
MySQL > Quit
Then modify the configuration file and delete the previously added line skip Grant
#vi/etc/my.cnf//Edit the My.cnf file to remove the previously added skip Grant line
Restart MySQL Service
#/etc/init.d/mysqld restart
#mysql-uroot-p ' aminglinux '//Verify that you can log in with the new password

Second, connect MySQL

#mysql-uroot-p123456//link-local Database
#mysql-uroot-p123456-h127.0.0.1-p3306//a Machine remote connection B machine, need to specify IP and port number
#mysql-uroot-p123456-s/tmp/mysql.sock//sock connection, only suitable for use in native
#mysql-uroot-p123456-e "Show Databases"//list all databases, typically used in shell scripts

Third, MySQL common commands

MySQL > show databases; What databases are queried
mysql > Use MySQL; Switch to the MySQL library below
MySQL > Show tables; View the table inside the library
mysql > DESC user; View the fields inside the user table
MySQL > Show create table user\g; See how a table is created, that is, to view the Build table statement, \g is a vertical display
MySQL > select * from User\g; Plus \g, it's a regular show of content.
MySQL > select User (); See which user is logged on by the current user
mysql > select database (); View the name of the database currently in use

MySQL > CREATE database db1; Create a DB1 Library
MySQL > show databases;
MySQL > CREATE table t1 (idInt (4),nameCHAR (40)); Create a T1 table, the first field is the ID, the second field is the name
MySQL > Show create table t1\g; You can see the contents of the table
mysql > drop table t1; Delete Table T1
MySQL > CREATE table t1 (idInt (4),namechar (+)) Engine=innodb DEFAULT Charset=utf8; Add a character set to create a T1 table
MySQL > Show create table t1\g; You can then see the contents of the table Engine=innodb DEFAULT Charset=utf8 displayed as UTF8
MySQL > select version (); View the current database version number
MySQL > Show status; View database Status
MySQL > show variables; View each parameter
MySQL > Show variables like ' max_connect% '; Use% pass match Max_connect related to out
MySQL > Set global max_connect_errors=1000; Modify the Max_connect_errors parameter value to 1000, if you need to restart the server or 1000, you need to modify the/ETC/MY.CNF
MySQL > Show processlist; View queues
MySQL > Show full processlist; View the full queue to see which users are connecting it, what to do when they connect it, and there are no lock tables

Set change root password to connect MySQL mysql common commands

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.