//修改输出格式为table mysql> set global log_output='TABLE'; mysql> show variables like '%log_output%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | TABLE | +---------------+-------+ mysql> select * from mysql.slow_log;
//修改输出格式为file mysql> set global log_output='FILE'; mysql> show variables like '%log_output%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | FILE | +---------------+-------+ 1 row inset (0.00 sec)
//设置慢查询时间(超过时间输出) mysql> set global long_query_time=10; mysql> show variables like 'long_query_time%'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 1 row inset (0.00 sec)
//打开关闭慢查询功能 mysql> set global slow_query_log=1; mysql> set global slow_query_log=0; mysql> show variables like 'slow_query%'; +---------------------+----------------------------------+ | Variable_name | Value | +---------------------+----------------------------------+ | slow_query_log | OFF | | slow_query_log_file | /mnt/data/mysql/3306/10-slow.log | +---------------------+----------------------------------+
Parse and summarize the MySQL slow query log. Options are --verbose verbose --debug debug --help write this text to standard output -v verbose -d debug -s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default al: average lock time ar: average rows sent at: average query time c: count l: lock time r: rows sent t: query time -r reverse the sort order (largest last instead of first) -t NUM just show the top n queries -a don't abstract all numbers to N and strings to 'S' -n NUM abstract numbers with at least n digits within names -g PATTERN grep: only consider stmts that include this string -h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard), default is '*', i.e. match all -i NAME name of server instance (if using mysql.server startup script) -l don't subtract lock time from total time
[root@192 mysql-5.6.35]# /mnt/app/mysql/bin/mysql -S /mnt/data/mysql/3306/mysql.sock mysql> GRANT REPLICATION SLAVE ON *.* to 'repl'@'%' identified by 'repl123'; mysql> flush privileges;
2.对用户和角色授权 postgres=# grant all privileges on database mydb to iuser; GRANT postgres=# grant all privileges on database mydb to irole; GRANT
3.使用用户登录数据库mydb,查看当前的模式 [smallasa@localhost ~]$ /mnt/app/pgsql/bin/psql -d mydb -U iuser psql (9.6.1) Type "help"forhelp. mydb=> \dn List of schemas Name | Owner --------+---------- public | smallasa (1 row)
说明: 数据库默认有一个public模式
4.在mydb中创建一张表,并查看表的映射关系 mydb=> CREATE TABLE test(id integer not null); CREATE TABLE mydb=> \d List of relations Schema | Name | Type | Owner --------+------+-------+------- public | test | table | iuser (1 row)
[root@localhost app]# tar xzf postgresql-9.6.1.tar.gz [root@localhost app]# cd postgresql-9.6.1 [root@localhost postgresql-9.6.1]# ./configure --prefix=/mnt/app/pgsql [root@localhost postgresql-9.6.1]# make [root@localhost postgresql-9.6.1]# make install
2. 插件安装
1 2
[root@localhost postgresql-9.6.1]# cd contrib/ [root@localhost contrib]# make install
补充: 安装一个插件
1 2
[root@localhost postgresql-9.6.1]# cd contrib/pgcrypto/ [root@localhost pgcrypto]# mkdir install
3. 环境变量设置
1 2 3 4
[root@localhost postgresql-9.6.1]# echo 'export PGSQL_HOME=/mnt/app/pgsql' | tee /etc/profile.d/postgresql.sh [root@localhost postgresql-9.6.1]# echo 'export PGSQL_BIN=${PGSQL_HOME}/bin' | tee -a /etc/profile.d/postgresql.sh [root@localhost postgresql-9.6.1]# echo 'export PATH=${PGSQL_BIN}:$PATH' | tee -a /etc/profile.d/postgresql.sh [root@localhost postgresql-9.6.1]# source /etc/profile
[root@localhost postgresql-9.6.1]# su - smallasa [smallasa@localhost ~]$ /mnt/app/pgsql/bin/initdb -D /mnt/data/pgsql/
6. 设置访问权限
1 2 3 4 5
[smallasa@localhost ~]$ vim /mnt/data/pgsql/pg_hba.conf local all all trust host all all 127.0.0.1/32 trust host all all ::1/128 trust host all all 0.0.0.0/0 md5
7. 修改配置文件
1 2 3 4
[smallasa@localhost ~]$ vim /mnt/data/pgsql/postgresql.conf listen_addresses = '\*' port = 5432 max_connections = 2000
[root@localhost app]# tar xzf postgresql-9.6.1.tar.gz [root@localhost app]# cd postgresql-9.6.1 [root@localhost postgresql-9.6.1]# ./configure --prefix=/mnt/app/pgsql [root@localhost postgresql-9.6.1]# make [root@localhost postgresql-9.6.1]# make install
2. 插件安装
1 2
[root@localhost postgresql-9.6.1]# cd contrib/ [root@localhost contrib]# make install
补充: 安装一个插件
1 2
[root@localhost postgresql-9.6.1]# cd contrib/pgcrypto/ [root@localhost pgcrypto]# mkdir install
3. 环境变量设置
1 2 3 4
[root@localhost postgresql-9.6.1]# echo 'export PGSQL_HOME=/mnt/app/pgsql' | tee /etc/profile.d/postgresql.sh [root@localhost postgresql-9.6.1]# echo 'export PGSQL_BIN=${PGSQL_HOME}/bin' | tee -a /etc/profile.d/postgresql.sh [root@localhost postgresql-9.6.1]# echo 'export PATH=${PGSQL_BIN}:$PATH' | tee -a /etc/profile.d/postgresql.sh [root@localhost postgresql-9.6.1]# source /etc/profile
[root@localhost postgresql-9.6.1]# su - smallasa [smallasa@localhost ~]$ /mnt/app/pgsql/bin/initdb -D /mnt/data/pgsql/
2. 设置访问权限
1 2 3 4 5 6
[smallasa@localhost ~]$ vim /mnt/data/pgsql/pg_hba.conf local all all trust host all all 127.0.0.1/32 trust host all all ::1/128 trust host replication repl 192.168.0.0/16 md5 =>追加语句 host all all 192.168.0.0/16 md5 =>其它用户访问策略
[root@smallasa ~]# mkfs.xfs /dev/vdb [root@smallasa ~]# echo '/dev/vdb /mnt xfs defaults 0 0' | tee -a /etc/fstab [root@smallasa ~]# mount -a
4. 设置打开最大文件数
1 2 3 4 5 6 7
[root@smallasa ~]# echo '* - nproc 65535' | tee -a /etc/security/limits.conf [root@smallasa ~]# echo '* - nofile 65535' | tee -a /etc/security/limits.conf [root@smallasa ~]# ls /etc/security/limits.d/*|xargs rm -f
echo'* - nproc 65535' | tee -a /etc/security/limits.conf echo'* - nofile 65535' | tee -a /etc/security/limits.conf ls /etc/security/limits.d/*|xargs rm -f
enable-cache group yes positive-time-to-live group 3600 negative-time-to-live group 60 suggested-size group 211 check-files group yes persistent group yes shared group yes max-db-size group 33554432 auto-propagate group yes