一 设置更改root密码
启动MySQL:/etc/init.d/mysqld start
把环境变量添加到/etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
设置密码登录
[root@greg02 vhost]#mysqladmin -uroot password 'greg1617';
Warning: Using a password on the command line interface can be insecure.
[root@greg02 vhost]#mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@greg02 vhost]#mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
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>
更改密码
mysqladmin -uroot -p'greg1617' password 'greg1618';
MySQL忘记密码怎么办?
[root@greg02 src]#vim /etc/my.cnf
增加skip-grant
[root@greg02 src]#/etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@greg02 src]#mysql –uroot即可登录
use mysql;
select password from user where user='root';
update user set password=password('greg1617') where user='root';也能更改密码。
不用密码不安全,vim /etc/my.cnf
去掉skip-grant
[root@greg02 src]#mysql -uroot -p'greg1617';重新用新密码登录
二 连接MySQL
mysql -uroot -p123456
mysql -uroot -p123456 -h127.0.0.1 -P3306 //host和port,可以在这里更改端口
mysql -uroot -p123456 -S/tmp/mysql.sock //socket方式连接,默认;连接/tmp/mysql.sock
mysql -uroot -p123456 -e "show databases" //使用-e执行一些命令
三 MySQL常用命令
查询库 show databases;
切换库 use mysql;
查看库里的表 show tables;
查看表里的字段 desc tb_name;
查看建表语句 show create table tb_name\G;
查看当前用户 select user();
查看当前使用的数据库 select databsase();
创建库 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;
less /root/.mysql_history可以查看MySQL使用的历史命令。