mysql数据库管理方法,mysql数据库操作

时间:2024-01-03 01:10:50/人气:433 ℃

作者:是烫的不是自来卷

一:数据库(MySQL)

1 备份命令

# mysqldump -uroot -pDbb790827253 -h192.168.0.180 --all-databases --single_transaction --flush-log --master-data=2 --lock-tables > /data/mysqlbackup.sql

导入

#mysql -uzabbix -p123456 -h172.20.100.3 zabbix< database/mysql/schema.sql

2 创建库和用户命令创建库

mysql> create database zabbix character set utf8 collate utf8_bin;

授权用户

mysql> grant all privileges on zabbix.* to zabbix@"%" identified by '123456';

3 主从命令

mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'rsync-user'@'172.20.100.%' IDENTIFIED BY '123456';mysql> CHANGE MASTER TO MASTER_HOST='172.20.100.3',MASTER_USER='rsyncuser',MASTER_PASSWORD='123456',MASTER_LOG_FILE='bin-log.xxxxxx',MASTER_LOG_POS=xxx;

4 查询语句

mysql> show variables like '%connect%';

mysql> show variables like '%max_connections%';

mysql> desc notice_config;

mysql> show master logs;

查看连接数

mysql> show processlist;

mysql> show processlist \G;

5 查询mysql的日志问题

# memory

6查看用户和密码 修改密码查看到用户和密码

MySQL [(none)]> select host,user,password from mysql.user;

如果要修改密码的话,在命令行下执行下面的语句

update mysql.user set password='这里填写你要设置的密码' where user='root';

update user set password=password('123456') where user='root' and host='localhost';

7查看数据库的配置在里面

mysql> show variables like 'pxc_strict_mode%';

8 修改数据库密码

安装完数据库第一次设置密码方式 输完命令按回车,不用在下面输入。

#mysqladmin -u root -p password 123456

Enter password:

其设置密码有三种方法:

a. ./mysqladmin -u root -p oldpassword newpasswd(记住这个命令是在/usr/local/mysql/bin中外部命令)

b. SET PASSWORD FOR root=PASSWORD(’new password’);(对登录数据库后这种方式)

c. UPDATE user SET password=PASSWORD(”new password”) WHERE user=’root’; (对登录数据库后这种方式)

生效

mysql> flush privileges;

数据库sql语句

查询数据库表的大小

SELECT table_name AS "Tables",

round(((data_length index_length) / 1024 / 1024), 2) "Size in MB"

FROM information_schema.TABLES

WHERE table_schema = 'zabbix'

ORDER BY (data_length index_length) DESC;

9 增加root远程权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

flush privileges;

10:#skip-grant-tables 无视密码登录

11:安装mariadb数据库

#yum -y install mariadb mariadb-server

#systemctl start mariadb

#systemctl enable mariadb

接下来进行MariaDB的相关简单配置,设置密码,会提示先输入密码

[root@test-vm03 ~]# mysql_secure_installation

首先是设置密码,会提示先输入密码

Enter current password for root (enter for none):<–初次运行直接回车

设置密码

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车

New password: <– 设置root用户的密码

Re-enter new password: <– 再输入一次你设置的密码

其他配置

Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车

Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,

Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车

Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

12 配置MariaDB的字符集

接下来配置MariaDB的字符集:

-> 首先是配置文件/etc/my.cnf,在[mysqld]标签下添加

init_connect='SET collation_connection = utf8_unicode_ci'

init_connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_unicode_ci

skip-character-set-client-handshake

-> 接着配置文件/etc/my.cnf.d/client.cnf,在[client]中添加

default-character-set=utf8

-> 然后配置文件/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加

default-character-set=utf8

13创库和授权

mysql数据库

create database zabbix default character set utf8 collate utf8_bin;

grant all on zabbix.* to 'zabbix'@'%' identified by '123456';

flush privileges;

14:修改最大连接数

MYSQL修改最大连接数

方法一:

set GLOBAL max_connections=512;

这种方法在重启服务后会失效

方法二:

修改mysql配置文件my.cnf,在[mysqld]段中添加或修改max_connections值:

max_connections=512

MariaDB修改最大连接数

1.mariadb数据库最大连接数,默认为151

MariaDB [(none)]> show variables like 'max_connections';

----------------- -------

| Variable_name | Value |

----------------- -------

| max_connections | 151 |

----------------- -------

2.配置/etc/my.cnf

[mysqld]下新添加一行如下参数:

max_connections=3000

systemctl restart mariadb 重启mariadb服务,再次查看mariadb数据库最大连接数,最大连接数是214,并非我们设置的3000。

MariaDB [(none)]> show variables like 'max_connections';

----------------- -------

| Variable_name | Value |

----------------- -------

| max_connections | 214 |

----------------- -------

由于mariadb有默认打开文件数限制

vi /usr/lib/systemd/system/mariadb.Service

取消[Service]前的#号,

[Service]新添加两行如下参数:

LimitNOFILE=10000

LimitNPROC=10000

4.重新加载系统服务,并重启mariadb服务

systemctl --system daemon-reload

systemctl restart mariadb.service

再次查看mariadb数据库最大连接数,可以看到最大连接数已经是3000

MariaDB [(none)]> show variables like 'max_connections';

推荐

  • 1与珍惜时间相关的名言147
  • 2去香港旅游攻略286
  • 3吃鸡怎么找队友123
  • 4废旧电池倡议书190
  • 5有关青年干部培训的心得体会范文386
  • 6心愿作文500字保护环境348
  • 7人力资源培训心得体会179
  • 8白羊座与什么星座最相配431
  • 9歌手云飞与前妻离婚原因 老公星光大道成名后和她离婚345
  • 10屈老师语言教案小班,屈老师小班语言教案一朵小花359
  • 首页/电脑版/地图
    © 2024 OONiu.Com All Rights Reserved.