您的位置:首页 > 数据库 > MySQL

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql