[root@linux-10 ~]# /etc/init.d/mysqld start Starting MySQL SUCCESS!
vim /etc/profile export PATH=$PATH:/usr/local/mysql/bin/
[root@linux-10 ~]# source /etc/profile
[root@linux-10 ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server 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 its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
登陆时加-u选项可指定登陆的用户,-p选项可指定登陆用户的密码mysql
mysql -uroot -p'123456'
-p后输入的密码最好用单引号引用,避免密码中存在特殊符号致使系统不识别。linux
mysql> quit Bye [root@linux-10 ~]# mysqladmin -uroot password '123456' Warning: Using a password on the command line interface can be insecure. //警告的意思是密码被明文显示在屏幕上是不安全的
mysqladmin -uroot -p'旧密码' password '新密码'
vim /etc/my.cnf
skip-grant的做用是忽略受权,意思是操做数据库时能够直接登陆,无需密码。sql
use mysql //使用MySQL库
mysql> update user set password=password('12345678') where user='root'; //将root用户密码改成12345678 Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
将skip-grant删除,避免用户能够直接登陆数据库,下降风险shell
vim /etc/my.cnf//删除skip-grant
/etc/init.d/mysqld restart
[root@linux-10 ~]# mysql -uroot -p'12345678' Warning: 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 3 Server 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 its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
MySQL数据库已经能够经过新密码登陆。数据库
mysql -uroot -p123456 //输入用户名和密码
mysql -uroot -p123456 -S/tmp/mysql.sock //指定本机监听的sock文件
mysql -uroot -p123456 -h127.0.0.1 -P3306 //须要额外指定IP和端口号
mysql -uroot -p123456 -e “show databases” //登陆同时显示出全部的数据库
在MySQL中的操做须要添加分号。vim
show databases;
use mysql;
show tables;
desc tb_name;
注:表里的字段至关于咱们平常使用的表的表头。安全
show create table tb_name\G;
\G可让输出的结果更加规整,在执行sql语句时也能够加\G测试
select user();
注:MySQL的命令历史在Linux系统的root目录下的.mysql_history文件存放。ui
select databsase();
create database 数据库名称;
use 数据库名称; create table 表名称(`字段名称` int(4), `字段名称` char(40)); //字段名称后是每一个字段的字段类型
select version();
show status;
show variables; show variables like 'max_connect%';//查看指定参数,%是通配符,表明包含百分号以前内容的参数
set global max_connect_errors=1000;
注:修改的参数会在重启后恢复,想要永久生效须要在配置文件中进行更改。spa
show processlist; show full processlist;//会将最后一行(info)的信息显示彻底