Tag Archives: mysql

Day03.Mysql字段值操作

mysql> show engines; +——————–+———+—————————————————————-+————–+——+————+ | Engine | Support | Comment | Transactions | XA | Savepoints | +——————–+———+—————————————————————-+————–+——+————+ | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MRG_MYISAM | … Continue reading

Posted in mysql | Tagged | Leave a comment

Day02.Mysql基本操作

1,创建2个表,练习约束条件 mysql> create database test; Query OK, 1 row affected (0.00 sec) mysql> use test; Database changed mysql> create table tea(name varchar(4) not null,gender enum(‘boy’,’girl’) default “boy”,interest set(‘book’,’film’,’music’,’football’)); Query OK, 0 rows affected (0.36 sec) mysql> desc tea; +———-+—————————————+——+—–+———+——-+ | … Continue reading

Posted in mysql | Tagged | Leave a comment

Day01.Mysql初始化安装

[root@50 mysql]# grep password /var/log/mysqld.log 2018-09-06T03:35:28.791445Z 1 [Note] A temporary password is generated for root@localhost: <:6hlKMNfoUM

Posted in mysql | Tagged | Leave a comment

Day15.Mycat分库分表

Mycat 分库分表 IP规划 client 192.168.4.254 Mycat 192.168.4.56 c1 192.168.4.55 c2 192.168.4.54 [root@56 ~]# tar -xf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz [root@56 ~]# ll 总用量 985192 -rw——-. 1 root root 1838 1月 30 2018 anaconda-ks.cfg -rw-r–r–. 1 root root 169714648 9月 17 17:10 databases2.sql -rw-r–r–. … Continue reading

Posted in mysql | Tagged | Leave a comment

Day14.Mysql视图

mysql> select * from user; +—-+———————+——+——+——+—————————————————————–+—————————+—————-+——+———-+———-+ | id | username | pass | uid | gid | comment | homedir | shell | sex | homedir2 | pay | +—-+———————+——+——+——+—————————————————————–+—————————+—————-+——+———-+———-+ | 1 | root | x | 0 | 0 … Continue reading

Posted in mysql | Tagged | Leave a comment

Day13.MHA高可用配置方法

物理备份 rm -rf /var/lib/mysql/* systemctl stop mysqld rm -rf /var/lib/mysql 把刚才的备份文件拷贝到的当前库下 scp 192.168.4.50:/root/mysql.bak /var/lib/mysql/ 重启正常 重新初始化数据库 1、停数据库服务 systemctl stop mysqld 2、删除库 rm -rf /var/lib/mysql/* 3、重新启动,mysql数据库会自己检测 [root@51 mysql]# grep password /var/log/mysqld.log | tail 2018-09-13T02:33:34.691299Z 0 [Note] Shutting down plugin ‘sha256_password’ 2018-09-13T02:33:34.691305Z … Continue reading

Posted in mysql | Tagged | Leave a comment

Day11.Mysql主从配置

1、配置主-从-从结构,并做各种测试 第一步,配置主库51 vim /etc/my.cnf [root@51 mysql]# grep -v “^#” /etc/my.cnf | grep -v “^$” [mysqld] validate_password_policy = 0 validate_password_length = 6 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid log-bin=master51 server_id=51 binlog_format=”mixed” [root@51 mysql]# systemctl restart mysqld [root@51 mysql]# mysql -uroot -p123456 mysql> … Continue reading

Posted in mysql | Tagged | Leave a comment

Mysql插入中文时提示:ERROR 1366 (HY000): Incorrect string value: ‘\xE5\x8F\xB0\xE5\xBC\x8F…

原因:插入字段时提示错误: mysql> insert into 学生表 values (“张三丰”,”武当山”),(“章司封”,”二郎山”); ERROR 1366 (HY000): Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89…’ for column ‘姓名’ at row 1 分析: mysql> show create table 学生表 ; | Table | Create Table | | 学生表 | CREATE TABLE `学生表` ( … Continue reading

Posted in mysql | Tagged | Leave a comment

mysql salve从库设置read only 属性

在MySQL数据库中,在进行数据迁移和从库只读状态设置时,都会涉及到只读状态和Master-slave的设置和关系。 经过实际测试,对于MySQL单实例数据库和master库,如果需要设置为只读状态,需要进行如下操作和设置: 将MySQL设置为只读状态的命令: # mysql -uroot -p mysql> show global variables like “%read_only%”; mysql> flush tables with read lock; mysql> set global read_only=1; mysql> show global variables like “%read_only%”; 将MySQL从只读设置为读写状态的命令: mysql> unlock tables; mysql> set global read_only=0; 对于需要保证master-slave主从同步的salve库,如果要设置为只读状态,需要执行的命令为: mysql> set … Continue reading

Posted in mysql | Tagged | Leave a comment

mysql 中 sync_binlog 参数作用

sync_binlog”:这个参数是对于MySQL系统来说是至关重要的,他不仅影响到Binlog对MySQL所带来的性能损耗,而且还影响到MySQL中数据的完整性。对于“sync_binlog”参数的各种设置的说明如下: sync_binlog=0,当事务提交之后,MySQL不做fsync之类的磁盘同步指令刷新binlog_cache中的信息到磁盘,而让Filesystem自行决定什么时候来做同步,或者cache满了之后才同步到磁盘。 sync_binlog=n,当每进行n次事务提交之后,MySQL将进行一次fsync之类的磁盘同步指令来将binlog_cache中的数据强制写入磁盘。 在MySQL中系统默认的设置是sync_binlog=0,也就是不做任何强制性的磁盘刷新指令,这时候的性能是最好的,但是风险也是最大的。因为一旦系统Crash,在binlog_cache中的所有binlog信息都会被丢失。而当设置为“1”的时候,是最安全但是性能损耗最大的设置。因为当设置为1的时候,即使系统Crash,也最多丢失binlog_cache中未完成的一个事务,对实际数据没有任何实质性影响。 从以往经验和相关测试来看,对于高并发事务的系统来说,“sync_binlog”设置为0和设置为1的系统写入性能差距可能高达5倍甚至更多

Posted in mysql | Tagged | Leave a comment