Client login and
interactive login to
MySQL –h –u –p –P DBNAME –e “sql”
-u is the meaning of user, generally can be written directly as –uroot or –u MySQL
-h refers to the meaning of host IP –h192.168.1. 120. Set the user to be able to access remotely.
-p means password, you can write the password directly -pP@ssw0rd or don't write password for security -p
-P means port, for multi-instance mylsq, you can choose port login -p3306
DNNAME refers to the database name, you can write the database name directly
-e is used to execute statements
[root@MySQL ~]# MySQL -h 192.168.1.120 -uroot -pP@ssw0rd -P3306 test001
non-interactive use
-e
[root@ MySQL ~]# MySQL -h 192.168.1.120 -uroot -pP@ssw0rd -P3306 -e "show databases;" >>/root/shell/test.sql
Other
; and \g means that a sentence is written
\h or \? is the representative to check and help the
client login and forget the password
Edit the my.cnf file in MySQL 5.7.6 or later,
regardless of source code compilation, binary compilation, or yum installation and rpm installation,
add
[MySQLd]
skip-grant-tables
[root@MySQLgeneric ~]# vi /etc/my.cnf
restart MySQL service
[ root@MySQLsource ~]# service MySQLd restart
Log in to the MySQL database
[root@MySQLsource ~]# MySQL
view MySQL permissions content
MySQL> desc MySQL.user;
MySQL> select user,host,authentication_string from MySQL.user;
modify password
MySQL> update MySQL .user set authentication_string=password('P@ssw0rd123') where user='root';
modify back to the my.cnf file and restart the MySQL server
[root@MySQLsource ~]# vi /etc/my.cnf
log in to the database
[root@ MySQLsource ~]# MySQL -uroot -pP@ssw0rd123 MySQL
versions before 5.7.5