Set change root password, connect MySQL, MySQL common commands

Source: Internet
Author: User
Tags local time

设置更改root密码

The default Mysqlroot user's password is empty, but this is not secure, so we need to configure the security password

#mysql -uroot  mysq命令默认是不存在的,因为mysql安装在/usr/local/mysql/bin下,环境变量里面不存在mysql命令,需要将命令加在环境变量里面#export PATH=$PATH:/usr/local/mysql/bin  ,想永久生效需要放在/etc/profile里面,然后执行#source /etc/profile
#vim /etc/profile              //加入如下内容
export PATH=$PATH:/usr/local/mysql/bin
#source /etc/profile  
#mysql -uroot -p 123456             //-p指定它的密码,quit退出
#mysqladmin -uroot -p ‘123456‘ password ‘00000‘      //更改密码
当我们不知道mysql的密码时,更改密码的步骤#vim /etc/my.cnf                    //再[mysqld]下增加skip-grant ,忽略授权
skip-grant
#/etc/init.d/mysqld restart                          //重启mysql服务  
#mysql -uroot              //这时候登录不需要密码,登录进去后需要更改一个表,密码存放在mysql库里 #use mysql;                 //切换到mysql库
#select *from user;       //查看user表,这里面存放用户的权限,密码等
#update user set password=password(‘zenwenlinux‘) where user=‘root‘;     //更改密码完毕
mysql> update user set password=password(‘123456‘) where user=‘root‘;Query OK, 4 rows affected (0.02 sec)Rows matched: 4  Changed: 4  Warnings: 0
#最后将/etc/my.cnf里面的skip-grant删除,然后/etc/init.d/mysqld  restart重启mysql服务
             mysql5.7root有默认的密码,必须重设密码,才能进行mysql的操作
1.查看默认的密码
[[email protected] src]# cat /root/.mysql_secret# The random password set for the root userat Fri Jan 10 20:00:34 2014 (local time): aJqZsA2m这里的aJqZsA2m就是生成的root随机密码啦
2.登录mysql
[[email protected] src]# mysql -u root -pEnter password:输入上面的密码aJqZsA2m登录,如果你没有把mysql的路径加到path里,那就用绝对路径,mysql -u root -p还可以写成mysql -uroot -paJqZsA2m
3.更改密码
mysql> SET PASSWORD  FOR ‘root‘@localhost = PASSWORD(‘123456‘);Query OK, 0 rows affected (0.17 sec)至此,就成功地修改了密码。
                                         连接mysql
mysql服务启动时,不仅会监听IP:Port,还会监听一个socket,我们安装的mysql是监听在/tmp/mysql.sock.如果php在本地,那么php和mysql通信就可以通过socket通信,如果是远程,就需要通过tcp/ip来进行通信了。
#mysql -uroot -p123456                       //登录本机的mysql,默认使用socket去连接
连接远程的mysql#mysql -uroot -p123456 -h127.0.0.1 -P3306              //-h指定ip,-P指定端口
#mysql -uroot -p123456 -S/tmp/mysql.sock            //-S指定它的socket,只适合在本机上
连接mysql操作命令#mysql -uroot -p123456 -e “show databases”     //-e指定执行的命令
                                      mysql常用命令
查看建表语句 show create table tb_name\G;  
mysql> show create table db1\G;*************************** 1. row ***************************       Table: db1Create Table: CREATE TABLE `db1` (  `id` int(4) DEFAULT NULL,  `name` char(40) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec)
查看当前使用的数据库 select databsase();
删除表 drop t1;
查看当前数据库版本 select version();
查看数据库状态 show status;
修改参数 set global max_connect_errors=1000;           想永久生效需要更改配置文件#vim /etc/my.cnf
查看队列 show processlist; show full processlist;

Set change root password, connect MySQL, MySQL common commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.