root登录mysql数据库_MySQL常用命令、正常登录数据库、重置root密码
root登录mysql数据库_MySQL常⽤命令、正常登录数据库、重
置root密码
更改mysql数据库的root密码
修改root密码命令为
/usr/local/mysql/bin/mysql -uroot蒸鱼的做法.教你如何蒸鱼视频
定义环境变量
临时定义环境变量
export PATH=$PATH:/usr/local/mysql/bin/ //临时定义环境变量
echo $PATH //显⽰环境变量
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin:/usr/local/mysql/bin/
永久定义环境变量
vim /etc/profile
增加代码
export PATH=$PATH:/usr/local/mysql/bin/
source /etc/profile //⽣效⽂件
登录MySQL
指定使⽤账号root密码登录,-u后⾯为账号,-p后⾯可以跟密码;
mysql -uroot -p
mysql -uroot -p'123456789'
设置密码
在空密码下指定密码为123456
mysqladmin -uroot password '123456'
在有密码的情况下修改密码
旧密码123456修改为123456789
mysqladmin -uroot -p'123456' password '123456789'
注意:不是在登录mysql⾥⾯修改,mysqladmin不是mysql命令,⽽是Linux系统命令;
忘记root密码
编辑配置⽂件
vim /etc/myf
在[mysqld]下增加⼀⾏skip-grant
预览
[mysqld]
开学典礼教师代表发言稿skip-grant //跳过密码验证
datadir=/data/mysql
socket=/tmp/mysql.sock
重启mysql服务
/etc/init.d/mysqld restart
登录mysql修改
mysql -uroot
use mysql;
update user set password=password('123456') where user='root';
取消配置⽂件配置
vim /etc/myf
取消代码
skip-grant
重启mysql服务
/etc/init.d/mysqld restart
测试验证
mysql -uroot -p'123456'
使⽤密码123456登录成功
连接MySQL
常⽤的连接命令
mysql -uroot -p'123456' //连接本机
mysql -uroot -p'123456' -h127.0.0.1 -P3306 //连接远程机器127.0.0.1为ip,3306为端⼝mysql -uroot -p'123456' -S/tmp/mysql.sock //使⽤sock⽅式连接,只适合本机连接
mysql -uroot -p'123456' -e "show databases" //列出mysql的所有数据库,⽤于shell命令mysql -uroot -p'123456' -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
MySQL常⽤命令
必须登录mysql才能使⽤的命令
使⽤命令后⾯必须加;号
查询库 show databases;
切换库 use mysql;
查看库⾥的表 show tables;
查看表⾥的字段 desc tb_name;
查看建表语句 show create table tb_name\G;
查询mysql所有⽤户和限制主机select user,host from user;礼仪服务
查询指定⽤户的权限show grants for '⽤户名'@'限制ip';
查看当前⽤户 select user();
查看当前使⽤的数据库 select database();
创建库 create database db1;
创建表 use db1; create table t1(id int(4), name char(40));
查看当前数据库版本 select version();
查看数据库状态 show status;
青岛必玩景点排行
查看各参数 show variables; show variables like 'max_connect%';修改参数 set global max_connect_errors=1000;
查看队列 show processlist; show full processlist;
查询库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
切换库
mysql> use mysql;
Database changed
查看库⾥⾯的表
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
梦幻西游门派介绍| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type | | user |
+---------------------------+
28 rows in set (0.00 sec)
查看表⾥⾯的字段
注意:格式是
desc [表名];
desc user;
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
空间霸气留言
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。