First, set the change root password
ps -ef |grep mysql //查看mysql是否启动,如果没有启动就执行下面命令启动/etc/init.d/mysqld start
- To log in to MySQL you need to execute the following command
/usr/local/mysql/bin/mysql -uroot
exit 或者quit退出mysql
- For ease of use
Change environment variable path, add MySQL absolute path
export PATH=$PATH:/usr/local/mysql/bin/
- Modify the file if you need to modify the persistent environment variable;
vim /etc/profile
Add to
Export path= $PATH:/usr/local/mysql/bin/
source /etc/profile //使修改后的变量生效
- MySQL default does not have root password, new root password
mysqladmin -uroot password ‘123456‘ mysql -uroot -p123456 //登陆mysql,指定用户密码
mysqladmin -uroot -p123456 password ‘qwerty‘
- Password reset (if you don't know the original password)
vi /etc/my.cnf //增加skip-grant,去除密码验证
重启mysql服务 /etc/init.d/mysqld restart
mysql -uroot ///登陆mysql use mysql; update user set password=password(‘123456‘) where user=‘root‘;
- After modifying the skip-grant in the configuration file, the commands in MySQL need to be separated by a semicolon ";" End two, connect MySQL
mysql -uroot -p123456 mysql -uroot -p123456 -h127.0.0.1 -P3306 //指定ip和端口,用于链接远程服务器的mysql mysql -uroot -p123456 -S/tmp/mysql.sock (只适合在本机,默认就是以sock方式登陆) mysql -uroot -p123456 -e “show databases” //登陆后运行特定的命令,一般用于shell脚本中
Third, MySQL common commands
查询库 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; //临时生效,永久生效需要修改mysql.cnf配置文件 查看队列 show processlist; show full processlist;
52.mysql command: Set change root password, connect MySQL, mysql common command