mysql基础操作
2016-05-10 20:32
801 查看
启动 关闭
/etc/init.d/mysqld start
netstat -lntup | grep 3306
ps -ef | grep mysql | grep -v grep
root 1946 1 0 01:51 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysql/data --pid-file=/application/mysql/data/lnmp.com.pid
mysql 2187 1946 0 01:51 pts/1 00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/lnmp.com.err --pid-file=/application/mysql/data/lnmp.com.pid --socket=/tmp/mysql.sock --port=3306
vim /etc/init.d/mysqld //启动过程
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/d ev/null 2>&1 &
mysqld_safe --user=mysql & //初始化时给出的启动方法
/etc/init.d/mysqld stop
ss -lnt | grep 3306
LISTEN 0 50 *:3306
killall mysqld pkill mysqld killall -9 mysqld //尽量不要粗鲁的关闭数据库
mysqladmin -uroot -p123456 shutdown
登陆
ifconfig //看是否是测试还是正式环境,,,备份数据库
mysql
mysql -uroot -p
mysql> prompt \u@hequanS \r:\m:\s-> //修改提示符
root@hequanS 02:13:09->
[mysql]
prompt \u@hequanS \r:\m:\s-> // /etc/my.cnf
帮助
mysql> help
exit
密码
mysqladmin -u root password'123456' //最常用 简单 实用
mysqladmin -u root -p'123456' password '123123'
select user,host,password from mysql.user;
mysql> update mysql.user set password=password(456) where user='root' and host='localhost'; //要指定条件
mysql> set password=password('123123');
mysql> flush privileges;
找回mysql root用户密码
/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables --user=mysql & //忽略授权表如果是编译的,默认是/usr/local/mysql 会有报错。
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
update user set password=password(新密码) where user='root' and host='localhost';==>设置新密码
flush privileges;==>刷新
新开窗口 mysqladmin -uroot -p shutdown ==>新密码测试关掉数据库,成功关闭就证明修改成功
//多实例要指定 mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables
mysqld_safe --skip-grant-tables --skip-networking &
// skip-networking
开启该选项后就不能远程访问MySQL
为安全考虑希望指定的IP访问MySQL,可以在配置文件中增加bind-address=IP,前提是关闭skip-networking
/etc/init.d/mysqld start
netstat -lntup | grep 3306
ps -ef | grep mysql | grep -v grep
root 1946 1 0 01:51 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysql/data --pid-file=/application/mysql/data/lnmp.com.pid
mysql 2187 1946 0 01:51 pts/1 00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/lnmp.com.err --pid-file=/application/mysql/data/lnmp.com.pid --socket=/tmp/mysql.sock --port=3306
vim /etc/init.d/mysqld //启动过程
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/d ev/null 2>&1 &
mysqld_safe --user=mysql & //初始化时给出的启动方法
/etc/init.d/mysqld stop
ss -lnt | grep 3306
LISTEN 0 50 *:3306
killall mysqld pkill mysqld killall -9 mysqld //尽量不要粗鲁的关闭数据库
mysqladmin -uroot -p123456 shutdown
登陆
ifconfig //看是否是测试还是正式环境,,,备份数据库
mysql
mysql -uroot -p
mysql> prompt \u@hequanS \r:\m:\s-> //修改提示符
root@hequanS 02:13:09->
[mysql]
prompt \u@hequanS \r:\m:\s-> // /etc/my.cnf
帮助
mysql> help
exit
密码
mysqladmin -u root password'123456' //最常用 简单 实用
mysqladmin -u root -p'123456' password '123123'
select user,host,password from mysql.user;
mysql> update mysql.user set password=password(456) where user='root' and host='localhost'; //要指定条件
mysql> set password=password('123123');
mysql> flush privileges;
找回mysql root用户密码
/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables --user=mysql & //忽略授权表如果是编译的,默认是/usr/local/mysql 会有报错。
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
update user set password=password(新密码) where user='root' and host='localhost';==>设置新密码
flush privileges;==>刷新
新开窗口 mysqladmin -uroot -p shutdown ==>新密码测试关掉数据库,成功关闭就证明修改成功
//多实例要指定 mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables
mysqld_safe --skip-grant-tables --skip-networking &
// skip-networking
开启该选项后就不能远程访问MySQL
为安全考虑希望指定的IP访问MySQL,可以在配置文件中增加bind-address=IP,前提是关闭skip-networking
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复