52.mysql command: set and change root password, connect to mysql, mysql common commands

1. Setting and changing the 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

52.mysql command: set and change root password, connect to mysql, mysql common commands

  • In order to facilitate the use of
    changing the environment variable PATH, increase the absolute path of mysql
export PATH=$PATH:/usr/local/mysql/bin/   
  • If you need to modify permanent environment variables, modify the file;
 vim   /etc/profile  

添加
export PATH=$PATH:/usr/local/mysql/bin/

52.mysql command: set and change root password, connect to mysql, mysql common commands

 source /etc/profile   //使修改后的变量生效
  • MySQL has no root password by default, create a new root password

mysqladmin -uroot password '123456'

 mysql -uroot -p123456  //登陆mysql,指定用户密码

52.mysql command: set and change root password, connect to mysql, mysql common commands

  • Change root password
mysqladmin -uroot  -p123456 password 'qwerty'
  • Password reset (if the original password is not known)
vi /etc/my.cnf                  //增加skip-grant,去除密码验证

52.mysql command: set and change root password, connect to mysql, mysql common commands

重启mysql服务 /etc/init.d/mysqld restart
mysql -uroot   ///登陆mysql
 use mysql;
 update user set password=password('123456') where user='root';
  • After modification, delete skip-grant in the configuration file; commands in mysql need to end with a semicolon ";"

    2. Connect to 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脚本中

3. 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 and change root password, connect to mysql, mysql common commands

52.mysql command: set and change root password, connect to mysql, mysql common commands

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325572406&siteId=291194637