MySQL Settings change root password, MySQL server connection, MySQL common commands

Source: Internet
Author: User

1. Set Change root password

Check MySQL startup or not, and run if it doesn't start:/usr/local/mysql56/bin/mysql
PS aux |grep mysql or netstat-tulnp |grep 3306
Running the MySQL command will appear:

-bash:mysql:command not found
Add MySQL to the environment variable:
Temporary add:paht= $PATH:/usr/local/mysql56/bin
Add permanently:echo "Export path= $PATH:/usr/local/mysql56/bin" >>/etc/profile
Then run Soucre/etc/profile or. /etc/profile

MySQL password settings, set the password for the root user

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

How to change your password:
Mysqladmin-uroot-p ' old_password ' password ' new_password ' or in the following way

Forgot the password how to modify:
First, you have to modify the configuration file:vim/etc/my.cnf
Add skip-grant to the [mysqld] module and restart the MySQL service:sed-i '/3306/a\skip-grant '/etc/my.cnf
Restart:/etc/init.d/mysqld restart

Then, switch the database: usemysql;
Then, change the root password in the database:update user set Password=password (' New_password ') where user= ' root ';
So we can change the code back.

Re-test, the my.cnf to change back:

2. mysql Connection
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. mysql Common commands

Query How many libraries: show databases;
use a library: use database_name;
See how many tables: show tables;
to view the fields in a table: DESC table_name:
View the command that was entered at the time of the creation of one of the tables: Span style= "COLOR: #ff0000" >show create table table_name\g;
to see which users are currently logged on: select user ();
view which library is currently in use: select database ();
to view the version of the current database: select version ();
View the various parameters that the configuration file can define: show variables;
View current number of processes: show processlist; or  show full processlist;  # This is the most used (that is, to see what the database is doing)


Creating a database: Create databasesdb_name;
Creating a table: CreateTable table_name (' name ' types (length), ' name ' type (length),........)

Creating a table: Createtable table_test (id int (), name char (+), sex int (4));

The first part is completed.

MySQL Settings change root password, MySQL server connection, 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.