####监控脚本

[root@pdb~]# more /opt/VRTS/scripts/mysql_monitor.sh

#!/bin/sh

n=`ps -ef |grep mysql|grep "port=3306"|wc -l`

if test $n -eq 0

then exit 100

else exit 110

fi

[root@pdb~]# sh /opt/VRTS/scripts/mysql_monitor.sh

##############2 启动

[root@pdb~]# cd /opt/VRTS/scripts/mysql_monitor.sh

[root@pdb~]# cd /opt/VRTS/scripts

[root@pdbscripts]# ls

mysql_monitor.sh start_mysql.sh stop_mysql.sh

[root@pdbscripts]# more start*.sh

base=/oa/oas_mysql/app/mysql/

datadir=/oa/oas_mysql/data/mydata

config_file=/oa/oas_mysql/app/mysql/my.cnf

user=mysql

/oa/oas_mysql/app/mysql/bin/mysqld_safe --defaults-file=${config_file} --datadir=${datadir} --user=$user &

#########3 停止

[root@pdbscripts]# more stop*.sh

/oa/oas_mysql/app/mysql/bin/mysqladmin -uroot -pmysql shutdown

 

 

#############sample mysql  sample 导入和导出

 

############mysql 导入导出

CREATE DATABASE `db_monitor` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

赋予数据库(zqxt)权限给某用户,可以是已经存在的用户或新用户名

GRANT ALL PRIVILEGES ON zqxt.* TO "任意用户名"@"localhost" IDENTIFIED BY "新密码";


刷新权限

FLUSH PRIVILEGES;


退出数据库shell

EXIT;

 

1.备份单个数据库的数据和结构(,数据库名mydb)

mysqldump -uroot-p123456 db_monitor>c:\db_monitor.sql

 

2.还原单个数据库(需指定数据库)

(1) mysql>use mydb

mysql>source f:\mydb.sql

(2) mysql -uroot -p123456 mydb <c:\db_monitor.sql

# 输入密码开始导入数据

#######command

https://dev.mysql.com/doc/refman/8.0/en/testing-server.html

If you specify a database name, mysqlshow displays a list of the tables within the database:

shell> bin/mysql -e "SELECT User, Host, plugin FROM mysql.user" mysql

shell> bin/mysqlshow mysql

Use mysqladmin to verify that the server is running. The following commands provide simple tests to check whether the server is up and responding to connections:

shell> bin/mysqladmin version

shell> bin/mysqladmin variables

 

###############phpadmin连接远程数据库

phpadmin连接远程数据库

1、打开wampserver下phpmyadmin的目录在D:\wamp\apps\下 D:\wamp\apps\phpmyadmin4.1.14

2、找到config.inc.php文件,打开修改要连接的远程MySQL的host,user和password,更改这3个信息即可

其中必须保证数据库有被远程连接的权限

/* Authentication type */

$cfg['Servers'][$i]['verbose'] = 'mysql wampserver';

//$cfg['Servers'][$i]['auth_type'] = 'cookie';

$cfg['Servers'][$i]['auth_type'] = 'config';

$cfg['Servers'][$i]['user'] = 'admin';

$cfg['Servers'][$i]['password'] = 'root';

/* Server parameters */

$cfg['Servers'][$i]['host'] = '192.168.1.154';

$cfg['Servers'][$i]['connect_type'] = 'tcp';

$cfg['Servers'][$i]['compress'] = false;

/* Select mysql if your server does not have mysqli */

$cfg['Servers'][$i]['extension'] = 'mysqli';

$cfg['Servers'][$i]['AllowNoPassword'] = true;

3.如果要用root登录此时也应该把host修改为localhost;


 

 

 

 

 

 

 

#######手工启停mysql

 

 

##section 1

10.241.95.221 (master)

##loging

su - mysql

mysql -P 3306 -uroot -pmysql

##with a non-default port

###mysql -S /mysql/mysql/data/mysqltmp/mysql_3307.sock -uroot -pmysql

##show master status

show master\G;

###shutdown db (with user mysql password mysql)

mysqladmin -uroot -p shutdown -S /mysql/mysql/data/mysqltmp/mysql.sock

###start db (with root)

/mysql/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/mysql/app/mysql/my.cnf &

 

##section 2

10.241.95.222 (slave)

###show slave staus

su - mysql

mysql -P 3306 -uroot -pmysql

##show slave status

show slave status\G;