mysql 更改root密码及 主机_设置更改root密码(远程,本地)、连接mysql、mysql常用命令...
設(shè)置更改root密碼
1、將mysql加入環(huán)境變量中
[root@centos7 ~]# grep mysql /etc/profile
export PATH=/usr/local/mysql/bin/:$PATH
2、直接登錄,無密碼
[root@centos7 ~]# mysql -uroot
3、方式一:設(shè)置密碼
[root@centos7 ~]# mysqladmin -uroot password '123456'
Warning: Using a password on the command line interface can be insecure.
You have new mail in /var/spool/mail/root
方式二:設(shè)置遠(yuǎn)程密碼和本地密碼
遠(yuǎn)程密碼:遠(yuǎn)程主機(jī)登錄使用
本地密碼:只能本機(jī)登錄使用
mysql> set password for 'root'@'localhost'=password('root');? ? ?????????????????????????#本地密碼
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT USAGE ON *.* TO 'root'@'%'? IDENTIFIED BY? '123456';???????????????#遠(yuǎn)程密碼
Query OK, 0 rows affected (0.00 sec)
查看:
mysql> select Host,User from mysql.user;
備注:(直接輸入mysql就可以登錄)
vi /etc/my.cnf
[client]
port? ? ? ? ? ? = 3306
user=root
password=root
4、登錄
[root@centos7 ~]# mysql -uroot -p'123456' -h127.0.0.1 -P3306
-h:指定主機(jī)
-P:指定端口
5、更改密碼為1234
[root@centos7 ~]# mysqladmin -uroot -p'123456' password '1234'
忘記密碼后,怎么更改?
1、[root@centos7 ~]# vi /etc/my.cnf
[mysqld]
skip-grant#跳過授權(quán)登錄
2、重啟mysql服務(wù)
[root@centos7 ~]# /etc/init.d/mysqld restart
3、[root@centos7 ~]# mysql -uroot
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password('123456') where user='root'; #更改密碼
4、將skip-grant配置刪除后重啟mysql服務(wù)
/etc/init.d/mysqld restart
5、已更改密碼
連接mysql
1、[root@centos7 ~]# mysql -uroot -p123456 -h127.0.0.1 -P3306
2、通過socket連接
[root@centos7 ~]# mysql -uroot -p123456 -S/tmp/mysql.sock
mysql常用命令
1、顯示所有數(shù)據(jù)庫
show databases;
2、進(jìn)入哪個(gè)數(shù)據(jù)庫
user db
3、顯示數(shù)據(jù)庫中所有的表
mysql> show tables;
4、顯示表結(jié)構(gòu)(由什么字段組成)
desc user;
5、查詢
select host,user from user;
6、顯示建表語句過程
show create table user\G;
7、顯示哪個(gè)用戶登錄
select user();
8、顯示表有多少行
select count(*) from user ;
9、顯示變量
show variables;
10、查找
show variables like '%error%';
11、設(shè)置臨時(shí)變量
mysql> set global max_connect_errors = 1000;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name? ? ? | Value |
+--------------------+-------+
| max_connect_errors | 1000? |
+--------------------+-------+
11、顯示mysql的進(jìn)程隊(duì)列
mysql> show processlist;
+----+------+-----------+-------+---------+------+-------+------------------+
| Id | User | Host? ? ? | db? ? | Command | Time | State | Info? ? ? ? ? ? ?|
+----+------+-----------+-------+---------+------+-------+------------------+
|? 3 | root | localhost | mysql | Query? ?|? ? 0 | init? | show processlist |
+----+------+-----------+-------+---------+------+-------+------------------+
1 row in set (0.01 sec)
mysql> show full? processlist;??#完整情況
+----+------+-----------+-------+---------+------+-------+------------------------+
| Id | User | Host? ? ? | db? ? | Command | Time | State | Info? ? ? ? ? ? ? ? ? ?|
+----+------+-----------+-------+---------+------+-------+------------------------+
|? 3 | root | localhost | mysql | Query? ?|? ? 0 | init? | show full? processlist |
+----+------+-----------+-------+---------+------+-------+------------------------+
12、新建表,字段
mysql> create table tb(`id` int,`num` varchar(10));
Query OK, 0 rows affected (0.02 sec)
mysql> show tables
-> ;
+----------------+
| Tables_in_test |
+----------------+
| tb? ? ? ? ? ? ?|
+----------------+
1 row in set (0.00 sec)
mysql> show create table tb;
+-------+--------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
+-------+--------------------------------------------------------------------------------------------------------------------------+
| tb? ? | CREATE TABLE `tb` (
`id` int(11) DEFAULT NULL,
`num` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------------------------------------+
mysql> desc tb;
+-------+-------------+------+-----+---------+-------+
| Field | Type? ? ? ? | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id? ? | int(11)? ? ?| YES? |? ? ?| NULL? ? |? ? ? ?|
| num? ?| varchar(10) | YES? |? ? ?| NULL? ? |? ? ? ?|
+-------+-------------+------+-----+---------+-------+
13、刪除庫及表
drop database test;
drop table tb;
14、插入數(shù)據(jù)
insert tb value(1,4);
本文轉(zhuǎn)自方向?qū)α?#xff0c;就不怕路遠(yuǎn)了!51CTO博客,原文鏈接:http://blog.51cto.com/jacksoner/1982740 ,如需轉(zhuǎn)載請自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的mysql 更改root密码及 主机_设置更改root密码(远程,本地)、连接mysql、mysql常用命令...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ddos攻击危害(ddos攻击安全吗)
- 下一篇: mysql 事实表 维度表_数据库的事实