Yum Repositorymysql
sudo yum install mysql-community-server
APTlinux
sudo apt-get install mysql-server
systemctl:sql
systemctl {start|stop|restart|status} mysqld
或者 service:docker
service mysqld {start|stop|restart|status}
第一次开启服务:shell
服务端初始化.数据库
SSL证书与密钥被生成,存放在数据文件夹中.bash
validate_password
is installed and enabled.session
超级用户:'root'@'localhost
被建立. 密码存放在日志中:ide
sudo grep 'temporary password' /var/log/mysqld.log
开启服务后设置密码:
mysql -uroot -p
ALTER USER 'root'@'%' IDENTIFIED BY 'MyNewPass';
Note:
密码要至少包含:
一个大写字母
user分为host为localhost
与%
的用户:
User@%
容许从全部的ip访问. User@localhost
只容许从localhost访问。(1)使用docker安装
拉取mysql
docker pull mysql:[tag]
启动镜像,配置挂载卷:
docker run -d -p 3306:3306 --name mysql \ -e MYSQL_ROOT_PASSWORD="assinscreed" \ -e MYSQL_USER="root" \ -e MYSQL_PASSWORD="assinscreed" \ mysql:[tag]
其中数据以及配置文件挂载:
--mount type=bind,src=/path-on-host-machine/my.cnf,dst=/etc/my.cnf \ --mount type=bind,src=/path-on-host-machine/datadir,dst=/var/lib/mysql \
若是输出数据的结果太宽,自动改为垂直显示,与sql语句以\G
做用相同。
--vertical
, -E
:强制垂直显示。
--html
, -H
输出为HTML格式,以下:
--xml
, -X
:输出为xml格式
--user=user_name
, -u user_name
--host=host_name
, -h host_name
--password[=password]
, -p[password
--port=port_num
, -P port_num
--database=db_name
, -D db_name
--wait
, -w
--skip-reconnect
.--execute=statement
, -e statement
--skip-line-numbers
.--safe-updates
. (Default value is 1,000,000.)--named-commands
, -G
能够在mysql中使用命令,如:quit
与\q
能够同时使用。
--skip-named-commands
:关闭长命令的使用。如可以使用\q
而quit
没法使用
--no-beep
, -b
--quick
, -q
--verbose
, -v
-v -v -v
produces table output format even in batch mode.)--version
, -V
mysql> help 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. query_attributes(\) Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up. For server side help, type 'help contents'
经常使用:
clear, \c
清空当前的输入,示例:
mysql> select wrong -> \c mysql>
connect [db_name [host_name]], \r [db_name [host_name]]
delimiter str, \d str
prompt [str], \R [str]
resetconnection, \x
重建链接,并清除seesion,示例:
mysql> SELECT LAST_INSERT_ID(3); +-------------------+ | LAST_INSERT_ID(3) | +-------------------+ | 3 | +-------------------+ mysql> SELECT LAST_INSERT_ID(); +------------------+ | LAST_INSERT_ID() | +------------------+ | 3 | +------------------+ mysql> resetconnection; mysql> SELECT LAST_INSERT_ID(); +------------------+ | LAST_INSERT_ID() | +------------------+ | 0 | +------------------+
source file_name, \. file_name
system commmand, \! command
tee [file_name], \T [file_name]
mysql> help contents You asked for help about help category: "Contents" For more information, type 'help <item>', where <item> is one of the following categories: Account Management Administration Data Definition Data Manipulation Data Types Functions Functions and Modifiers for Use with GROUP BY Geographic Features Language Structure Plugins Storage Engines Stored Routines Table Maintenance Transactions Triggers
可使用%
与_
,进行命令的匹配:
mysql> HELP rep% Many help items for your request exist. To make a more specific request, please type 'help <item>', where <item> is one of the following topics: REPAIR TABLE REPEAT FUNCTION REPEAT LOOP REPLACE REPLACE FUNCTION
读取文件中的SQ语句(经常使用于还原mysqldump备份的数据):
mysql db_name < text_file
若是文件中指定了数据库(use db_name),能够直接:
mysql < text_file
若是已经进入了mysql:
mysql> source file_name mysql> \. file_name