mysql的设置更改root密码、连接、常用命令

13.1 设置更改root密码

  • 更改环境变量PATH ,增加mysql绝对路径
    首次直接使用mysql会提示‘该命令不存在’,原因是还没有将该命令加入环境变量,如果要使用该命令,需要使用其绝对路径:/usr/local/mysql/bin/mysql,为了方便,先将其加入系统环境变量:
[[email protected] ~]# export PATH=$PATH:/usr/local/mysql/bin/

mysql命令路径暂时加入环境变量,系统重启后该变量会失效,若要永久生效,需要将其加入环境变量配置文件:

vi /etc/profile

#在配置文件最后 把上面的命令加

#执行source命令生效
[[email protected] ~]# source /etc/profile
  • 首次登陆
[[email protected] ~]# mysql -uroot

注: -p=passwd,使用密码登录,在此可以将密码直接输入在命令行(跟在-p后面,不加空格:-p‘123456‘<此处单引号可以不加,但是当密码中有特殊符号时必须加,所以在命令行输入密码时养成习惯:加单引号>),也可以不在命令行输入,只跟-p选项,然后根据提示信息:“Enter password”,输入密码进行登录(此方法不会暴露用户密码,安全)。

  • 设置mysql 的root密码 && 更改
[[email protected] ~]# mysqladmin -uroot password ‘123456‘
Warning: Using a password on the command line interface can be insecure.

[[email protected] ~]# mysql -uroot -p
Enter password:
#输入密码

#更改新的密码
[[email protected] ~]# mysqladmin -uroot -p‘123456‘ password ‘taoyuan‘
Warning: Using a password on the command line interface can be insecure.
[[email protected] ~]# mysql -uroot -p‘taoyuan‘
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
  • 密码重置
[[email protected] ~]# vi /etc/my.cnf

#my.cnf 配置文件内容
[mysqld]
skip-grant
datadir=/data/mysql #增加skip-grant
#忽略授权,意思是不用密码登陆

#重启mysql服务
[[email protected] ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS! 

#登陆mysql 修改一个表
mysql> use mysql;  #切换表
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

#查看表
mysql> select * from user;

#查看user表
mysql> select password from user;
+-------------------------------------------+
| password                                  |
+-------------------------------------------+
| *758ABA8398EF87C993D2C4420DACD8946907C873 |
|                                           |
|                                           |
|                                           |
|                                           |
|                                           |
+-------------------------------------------+
6 rows in set (0.00 sec)

#修改密码
mysql> update user set password=password(‘Aa123456‘) where user=‘root‘;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

#quit ,把/etc/my.cnf 配置文件修改回去 ,重启mysql服务
[[email protected] ~]# vi /etc/my.cnf
[[email protected] ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[[email protected] ~]# mysql -uroot -p‘Aa123456‘
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.

注: 完成该操作之后就可以任意登录mysql了(无需密码),所以此时mysql安全性很差,平时配置文件中一定不要添加该参数!!

13.2 连接mysql

  • 本机直接登陆
[[email protected] ~]# mysql -uroot -pAa123456
  • 通过端口连接(TCP/IP)
[[email protected] ~]# mysql -uroot -pAa123456 -h127.0.0.1 -P3306
# -P 指定端口
  • 使用sock的连接
[[email protected] ~]# mysql -uroot -pAa123456 -S/tmp/mysql.sock
#适用于本机连接
  • 连接mysql操作一个命令
[[email protected] ~]# mysql -uroot -pAa123456 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
#shell脚本使用中比较方便,可以直接获取数据

13.3 mysql常用命令

原文地址:http://blog.51cto.com/3622288/2060499

时间: 2024-08-08 09:05:29

mysql的设置更改root密码、连接、常用命令的相关文章

设置更改root密码 连接mysql mysql常用命令

一.设置更改root密码#/etc/init.d/mysqld start#ps aux |grep mysql#mysql -uroot //提示-bash: mysql : 未找到命令#ls /usr/local/mysql/bin/mysl //mysql实际启动路径#echo $PATH //查看PATH环境变量/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin#export PATH=$PATH:/usr/local/

13.1 设置更改root密码;13.2 连接MySQL;13.3 MySQL常用命令

扩展 : mysql5.7 root密码更改 http://www.apelearn.com/bbs/thread-7289-1-1.html myisam 和innodb引擎对比 http://www.pureweber.com/article/myisam-vs-innodb/ mysql 配置详解: http://blog.linuxeye.com/379.html mysql调优: http://www.aminglinux.com/bbs/thread-5758-1-1.html 同学

设置更改root密码、连接MYSQL、MYSQL常用命令

设置更改root密码 默认的mysqlroot用户的密码是空的,但是这样是不安全的,所以我们是需要配置安全密码的 #mysql -uroot mysq命令默认是不存在的,因为mysql安装在/usr/local/mysql/bin下,环境变量里面不存在mysql命令,需要将命令加在环境变量里面 #export PATH=$PATH:/usr/local/mysql/bin ,想永久生效需要放在/etc/profile里面,然后执行#source /etc/profile #vim /etc/pr

13.1 设置更改root密码13.2 连接mysql13.3 mysql常用命令

13.1 设置更改root密码查看mysql是否有启动,没有启动就先要启动将mysql加入变量PATH,再运行mysql uroot就可以执行了如果要让变量永久生效就加入/etc/profile下vi /etc/profile设置密码mysqladmin -uroot password '789159'再运行mysql uroot就无法登陆了,需要加-p,运行mysql uroot -p就可以登陆了更改密码还有一种情况不知道密码,可以取消受权,不用用户名与密码就可以登陆了vi /etc/my.c

MySQL常用操作(1)设置更改root密码、连接MySQL、MySQL常用命令

设置更改root密码 设置mysql的root用户密码:(默认为空) 1.查看mysql任务是否开启:ps aux |grep mysql 若无开启则-->/etc/init.d/mysqld start 2.登录mysql : /usr/local/mysql/bin/mysql -uroot (单独在命令行运行mysqlm命令是不生效的,因为mysql命令并不是在PATH 环境变量中定义) 若想不用在命令行中敲写绝对路径: (1)临时生效(重启失效) export PATH=$PATH:/u

52.mysql命令:设置更改root密码、连接mysql、mysql常用命令

一.设置更改root密码 ps -ef |grep mysql //查看mysql是否启动,如果没有启动就执行下面命令启动 /etc/init.d/mysqld start 登陆mysql需要执行下面的命令 /usr/local/mysql/bin/mysql -uroot exit 或者quit退出mysql 为了方便使用更改环境变量PATH,增加mysql绝对路径 export PATH=$PATH:/usr/local/mysql/bin/ 若需要修改永久环境变量则修改文件: vim /e

五十二、设置更改root密码、连接MySQL、MYSQL常用命令

一.设置更改root密码 root用户是MySQL的超级管理员用户,这个root和系统的root并不是一个用户,需要区分开,也可以创建普通用户来连接MySQL. 默认的MySQL的root用户密码是空的,可以直接连接上. # ps aux |grep mysql          先检查mysql有没有打开 # /etc/init.d/mysqld start # mysql -uroot -bash: mysql: 未找到命令 因为mysql这个命令没有在环境变量中,所以这个命令不能直接使用.

mysql设置更改root密码、mysql服务器的连接、mysql常用命令

 1.设置更改root密码 查看mysql 启动与否,若没启动就运行:/usr/local/mysql56/bin/mysqlps aux |grep mysql  或 netstat -tulnp |grep 3306运行mysql 命令,会出现: -bash: mysql: command not found就把mysql 添加到环境变量:临时添加:PAHT=$PATH:/usr/local/mysql56/bin永久添加:echo "export PATH=$PATH:/usr/local

设置更改root密码、连接MySQL、MySQL常用的命令

设置更改root密码 首先查看一下mysql有没有启动ps aux |grep mysql 如果没启动,就先启动mysql/etc/init.d/mysqld start 先将mysql目录加入环境变量中export PATH=$PATH:/usr/local/mysql/bin/ 再将命令写入到配置文件中,永久生效vim /etc/profile 在文件中添加如下的内容export PATH=$PATH:/usr/local/mysql/bin/ 设置mysql 密码mysqladmin -u