MySQL login and exit command format

MySQL login and exit command format

The command format for mysql login is:

mysql -h [hostip] -u [username] -p [password] [database]

1. Normal login mysql database command format: mysql -u username-p password, for example: mysql -u root -p root
root mysql -u root -p root
If no password is provided after -p, the user will be asked to enter the password after executing the command.

這里寫圖片描述

2. Set the port number to log in. The default port number of MySQL is 3306.
The command format is: mysql -u username-p password-P port number. Note that the letter P that specifies the port is uppercase, while the letter p that identifies the password is lowercase.

這里寫圖片描述

3. Specify the IP address and port number to log in to the MySQL database. The command format is: mysql -h ip -u user -p -P port number. For example: mysql -h 127.0.0.1 -u root -p -P 3306

這里寫圖片描述
這里寫圖片描述

4. Create a database login
mysql -h ip address -u username -p password database name For example: mysql -h 127.0.0.1 -u root -p test

View the currently logged in user and database

查看當前登陸用戶和數據庫命令

select user();
  select database();

Exit the login command and log in to MySQL. After entering, you may see the following prompt message. You can use help to see the output results.

mysql> help

For information about MySQL products and services, visit:
  http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
  http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
  https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.

For server side help, type 'help contents'

Through the output information, we know the following three commands to exit mysql
1. exit
2. quit
3. \q

This is the end of this article about the MySQL login and exit command format. For more relevant MySQL login and exit content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to the problem that MySQL commands cannot be entered in Chinese
  • Detailed explanation of encoding issues during MySQL command line operations
  • Introduction to the use of MySQL source command
  • MySQL commonly used SQL and commands from entry to deleting database and running away
  • Implementation of mysql using mysqlbinlog command to restore accidentally deleted data
  • Introduction to query commands for MySQL stored procedures
  • Three methods of automatically completing commands in MySQL database
  • MySQL password contains special characters & operation of logging in from command line
  • Mysql desktop tool SQLyog resources and activation methods say goodbye to the black and white command line
  • How to use the MySQL authorization command grant
  • Summary of MySQL basic common commands

<<:  Nginx local directory mapping implementation code example

>>:  Detailed explanation of component development of Vue drop-down menu

Recommend

W3C Tutorial (7): W3C XSL Activities

A style sheet describes how a document should be ...

Background gradient animation effect made by css3

Achieve results Implementation Code html <h1 c...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

How to use multi-core CPU to speed up your Linux commands (GNU Parallel)

Have you ever had the need to compute a very larg...

The best solution for resetting the root password of MySQL 8.0.23

This method was edited on February 7, 2021. The v...

Detailed explanation of basic syntax and data types of JavaScript

Table of contents Importing JavaScript 1. Interna...

VMware Workstation download and installation detailed tutorial

Virtual machines are very convenient testing soft...