MySQL common operations (top)

Source: Internet
Author: User

After the initial installation of MySQL, you can skip the password directly to MySQL.

[Email protected] ~]#/usr/local/mysql/bin/mysql-urootwelcome to the MySQL monitor. Commands End With; or \g.your MySQL connection ID is 1Server version:5.6.35 mysql Community Server (GPL) Copyright (c), Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>


Change Password

1. Change path, add MySQL path

[[email protected] ~]# export path= $PATH:/usr/local/ mysql/bin/[[email protected] ~]# mysql -urootwelcome to the mysql  Monitor.  commands end with ; or \g.your mysql connection id  is 2Server version: 5.6.35 MySQL Community Server  (GPL) Copyright   (c)  2000, 2016, Oracle and/or its affiliates. All rights  Reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql> 

This allows you to log in directly from the MySQL command, instead of writing the absolute path. If you want to take effect permanently, you must add it to the profile configuration.

2. Set the password

[[email protected] ~]# mysqladmin -uroot password  ' 123456 ' Warning: Using  a password on the command line interface can be insecure. [[email protected] ~]# mysql -urooterror 1045  (28000):  Access denied  for user  ' root ' @ ' localhost '   (using password: no) [[email protected] ~] # mysql -uroot -p123456warning: using a password on the command  line interface can be insecure. Welcome to the mysql monitor.  commands end with ; or \ g.your mysql connection id is 5server version: 5.6.35 mysql  community server  (GPL) copyright  (c)  2000, 2016, oracle and/or its  affiliates. all rights reserved. Oracle is a registered trademark of oracle corporation and/or itsaffiliates. other  Names may be trademarks of their respectiveowners. type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql>

3, change password

[[email protected] ~]# mysqladmin -uroot -p123456 password  ' ABCDEFG ' Warning :  using a password on the command line interface can be  insecure. [[Email protected] ~]# mysql -uroot -pabcdefgwarning: using a password  on the command line interface can be insecure. Welcome to the mysql monitor.  commands end with ; or \ g.your mysql connection id is 7server version: 5.6.35 mysql  community server  (GPL) copyright  (c)  2000, 2016, oracle and/or its  affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  itsaffiliates. other names may be trademarks of their  respectiveowners. type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql>

4, reset password when forgotten password

[[email protected] ~]# vi /etc/my.cnf[mysqld]skip-grant    # #新增该行, skip authorization ...... [[Email protected] ~]# /etc/init.d/mysqld restartshutting down mysql].  success! starting mysql. success! [[email protected] ~]# mysql - Urootwelcome to the mysql monitor.  commands end with ; or  \g.your mysql connection id is 1server version: 5.6.35 mysql  Community Server  (GPL) copyright  (c)  2000, 2016, Oracle and/or  Its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c ' &NBsp;to clear the current input statement.mysql> use mysql; reading table information for completion of table and column  Namesyou can turn off this feature to get a quicker startup  with -adatabase changedmysql> update user set password=password (' 88888888 ')  where user= ' root '; query ok, 4 rows affected  (0.01 sec) rows matched: 4  changed : 4  warnings: 0mysql> select password from user where  user= ' root '; +-------------------------------------------+| password                                    |+-------------------------------------------+|  *cb4ad0a70fccf86e95db2214f209acb191db847b | |  *cb4ad0a70fccf86e95db2214f209acb191db847b | |  *cb4ad0a70fccf86e95db2214f209acb191db847b | |  *cb4ad0a70fccf86e95db2214f209acb191db847b |+-------------------------------------------+4 rows  in set  (0.00 sec) mysql> exit; bye[[email protected] ~]# mysql -uroot -p88888888warning: using a  Password on the command line interface can be insecure. Welcome to the mysql monitor.  commands end with ; or \ g.your mysql connection id is 2server version: 5.6.35 mysql  community server  (GPL) copyright  (c)  2000, 2016, oracle and/or its  affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or itsaffiliates. other names may be trademarks of their  Respectiveowners. type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql>


Connect to MySQL

1. Remote connection to MySQL database

[[email protected] ~]# mysql -uroot -p88888888warning: using a  Password on the command line interface can be insecure. Welcome to the mysql monitor.  commands end with ; or \ g.your mysql connection id is 3server version: 5.6.35 mysql  community server  (GPL) copyright  (c)  2000, 2016, oracle and/or its  affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql> exit; Bye[[email protected] ~]# mysql -uroot -p88888888 -h127.0.0.1 -p3306warning: using a password on  The command line interface can be insecure. Welcome to the mysql monitor.  commands end with ; or \ g.your mysql connection id is 4server version: 5.6.35 mysql  community server  (GPL) copyright  (c)  2000, 2016, oracle and/or its  affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql>

2. Connect to the database using the socket

[[email protected] ~]# mysql-uroot-p88888888-s/tmp/mysql.sockwarning:using a password on the command line interface CA n be insecure.  Welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 5Server version:5.6.35 mysql Community Server (GPL) Copyright (c), Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>

3. Fast execution of commands outside the database

[[email protected] ~]# mysql-uroot-p88888888-e "show Databases" warning:using a password on the command line interface Can be insecure.+--------------------+| Database |+--------------------+| Information_schema | | MySQL | | Performance_schema | | Test |+--------------------+


Common commands

mysql> show databases;   # #显示数据库mysql > use mysql;         # #切换数据库mysql > show tables;      ## Show Table mysql> desc columns_priv;  # #查看columns_priv表mysql > show create  table columns_priv\g;  # #查看columns_priv的创建语句mysql > select user ();        # #查看当前登陆用户mysql > select database ();    # #查看当前数据库mysql > create database db1; # #创建数据库db1mysql > use db1;create table t1 ( ' ID '  int (4), ' name '  char (+));   # #创建数据库和表mysql > drop table t1;   # #删除表mysql > select version ();  # #查看mysql版本mysql > show status;     # #查看数据库状态mysql > show variables;  # #查看参数mysql > show variables  like  ' max_connect% ';   # #模糊查询参数mysql > set global max_connect_errors=1000;# #修改参数的值, to be permanently in force, in/etc/ MY.CNF Configuration mysql> show processlist;          ## View Queue mysql> show full processlist;     # #查看完整的队列信息


This article is from the "Gorilla City" blog, please be sure to keep this source http://juispan.blog.51cto.com/943137/1958191

MySQL common operations (top)

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.