[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)的信息顯示徹底