2014年6月26日木曜日

MySQLのテーブルエラー1064

Original post : http://anothermysqldba.blogspot.com/2014/06/mysql-table-error-1064.html

だから私は今日奇妙な状況に出くわした。 

私は、PHP $ _COOKIE ['PHPSESSID']の値を使用して、メモリテーブルを作成するシステムを持っている。 

いくつかの作業が完了すると、それは、テーブルをドロップします。 

2つのサンプルテーブルは、私の例については、以下である。 


@@VERSION: 5.6.19-log 
CREATE TABLE `f7a7a8d3a7ba75b5eb1712864c9b27eb` ( 
-> `id` int(11) NOT NULL AUTO_INCREMENT, 
-> PRIMARY KEY (`id`) 
-> ) ENGINE=MEMORY; 

CREATE TABLE `8865e52c7e1bea515e7156f240729275` ( 
-> `id` int(11) NOT NULL AUTO_INCREMENT, 
-> PRIMARY KEY (`id`) 
-> ) ENGINE=MEMORY; 


現在、いくつかの簡単な処理は、私は私がそれらを落としたように私はそれから使用実テーブルで発生します。 


DROP TABLE IF EXISTS f7a7a8d3a7ba75b5eb1712864c9b27eb; 
Query OK, 0 rows affected (0.09 sec) 


私はこの出会ったまで、十分に簡単.. 


desc 8865e52c7e1bea515e7156f240729275; 
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '8865e52c7e1bea515e7156f240729275' at line 1 

DROP TABLE IF EXISTS 8865e52c7e1bea515e7156f240729275; 
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '8865e52c7e1bea515e7156f240729275' at line 1 


今すぐ修正は実際には非常に簡単です。 しかし、問題は、なぜ1仕事と1は失敗しませんか? 

これを修正するには、単にテーブル名をバッククォート。 私はとにかく、最初から行っているはずである。 つまり、入るためにちょうど良い習慣です。 


DROP TABLE IF EXISTS `8865e52c7e1bea515e7156f240729275`; 
Query OK, 0 rows affected (0.02 sec) 


今、私が最初に多分問題は、英数字の名前だと思ったが、我々は1のバージョンが動作していることがわかります。 違いは、しかし、テーブル名の開始である。 ひとつは整数で、1は英字である。 だから、もう一度..このような愚かな間違いを避けるために、ベストプラクティスと引用テーブル名に従ってください。 


すべてのエラー·コードの後に​​構文解析エラーです.. 


perror 1064 
MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d 

2014年6月17日火曜日

MySQLのランダムな整数

Original post: http://anothermysqldba.blogspot.com/2014/06/mysql-random-integers.html

これは決して新しい機能ではありませんが、それは私がすべての今してポップアップ表示してしまっている質問です。 だから、簡単な例は以下の通りである。 

MySQLの内部にランダムな整数を生成するには、床やランド関数を使用することができます。 :このここにMySQLのマニュアルではhttp://dev.mysql.com/doc/refman/5.5/en/mathematical-functions.html#function_rand 

 私は= R <J、(私は、RAND()*(J + - I))式のフロアを使用した場合は、<範囲のランダムな整数Rを取得するには  

だから、例を与えるために: 

> SET @I = 3; # lower range 
> SET @J = 43 - @I; # max range minus lower range 

> SELECT FLOOR( @I + (RAND() * @J )) as lottery_numbers\G 
*************************** 1. row *************************** 
lottery_numbers: 4 
1 row in set (0.00 sec) 
> SELECT FLOOR( @I + (RAND() * @J )) as lottery_numbers\G 
*************************** 1. row *************************** 
lottery_numbers: 8 
1 row in set (0.00 sec 
> SELECT FLOOR( @I + (RAND() * @J )) as lottery_numbers\G 
*************************** 1. row *************************** 
lottery_numbers: 15 
1 row in set (0.00 sec 
> SELECT FLOOR( @I + (RAND() * @J )) as lottery_numbers\G 
*************************** 1. row *************************** 
lottery_numbers: 16 
1 row in set (0.00 sec 
> SELECT FLOOR( @I + (RAND() * @J )) as lottery_numbers\G 
*************************** 1. row *************************** 
lottery_numbers: 23 
1 row in set (0.00 sec 
> SELECT FLOOR( @I + (RAND() * @J )) as lottery_numbers\G 
*************************** 1. row *************************** 
lottery_numbers: 42 
1 row in set (0.00 sec 

2014年6月15日日曜日

Percona XtraDBクラスタをインストール

Original post: http://anothermysqldba.blogspot.com/2014/06/installing-percona-xtradb-cluster.html

だからもちろんPerconaは、プロセスを説明する資料を持っています。 このブログの目的は、誰かを助けることができる期待して、もう少し詳しく説明しに行くことです。 

レビューのためのハイパーリンク: 
前提条件 
  • ファイアウォールは、ポート3306、4444、4567および4568に接続できるようにセットアップされている
  • 内部ローカルネットワーク用のiptablesを停止するか、iptableのルールを調整します。
/etc/init.d/iptables stop 

  • SELinuxは無効になっています
echo 0 >/selinux/enforce 
vi /etc/selinux/config 

  • 最大のSSHキーを設定し、すべてのid_rsa.pubファイルの値はすべてのサーバのauthorized_keysにあるようにauthorized_keysにに入れる。
# ssh-keygen -t rsa 
# cd /root/.ssh/ 
# cp id_rsa.pub authorized_keys 
# chmod 600 /root/.ssh/authorized_keys 
# chmod 700 /root/.ssh/ 


だから私は、基本的なサーバのCentOS 6.5のインストールを始めています。 
# yum -y install http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm 
# yum -y install http://mirror.pnl.gov/epel/6/x86_64/epel-release-6-8.noarch.rpm 
# wget http://www.percona.com/downloads/RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona 
# wget http://www.percona.com/downloads/RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona 
# yum -y install socat 


私は、MySQL-LIBSおよび関連の依存関係を削除、衝突を避けるために 
# rpm -e mysql-libs postfix cronie redhat-lsb-core redhat-lsb-printing redhat-lsb-graphics libcgroup numad redhat-lsb sysstat crontabs cronie-anacron redhat-lsb-compat 


それから私は、Percona Clusterパッケージをインストールしました。 
# yum -y install Percona-XtraDB-Cluster-full-56 
[root@node1 ~]# /etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS! 
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'" 
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'" 
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'" 


だから我々は、我々は、ノードごとに削除された項目を置き換えることができます.. 
yum -y install postfix cronie redhat-lsb-core redhat-lsb-printing redhat-lsb-graphics libcgroup numad redhat-lsb sysstat crontabs cronie-anacron redhat-lsb-compat 


我々は次のクラスタを設定できるようにので、上記の手順を繰り返してパッケージをインストールします。 

[root@node2 ~]# /etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS! 
[root@node3 ~]# /etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)........ SUCCESS! 

私たちが実行してMySQLのの3つのインスタンスがありますが、それはまだ、クラスタではありません。 

ノードの構成

ノード1の/ etc / my.cnfに 
[mysqld] 

datadir=/var/lib/mysql 
user=mysql 

# Path to Galera library 
wsrep_provider=/usr/lib64/libgalera_smm.so 

# Cluster connection URL contains the IPs of node#1, node#2 and node#3 
# node 1 192.168.0.33 
# nod3 2 192.168.0.34 
# nod3 3 192.168.0.35 
wsrep_cluster_address=gcomm://192.168.0.33,192.168.0.34,192.168.0.35 

# In order for Galera to work correctly binlog format should be ROW 
binlog_format=ROW 

# MyISAM storage engine has only experimental support 
default_storage_engine=InnoDB 

# This changes how InnoDB auto increment locks are managed and is a requirement for Galera 
innodb_autoinc_lock_mode=2 

# Node #1 address 
wsrep_node_address=192.168.0.33 

# SST method 
#wsrep_sst_method=xtrabackup 
wsrep_sst_method=rsync # 
# wsrep_sst_method=rsync_wan # 
# wsrep_sst_method=mysqldump # SLOW 

# Cluster name 
wsrep_cluster_name=percona_cluster 

# Authentication for SST method 
wsrep_sst_auth="root:<password_here>" 

# server_id 
server_id=3232235553 #SELECT INET_ATON('192.168.0.33') 

#[client] 
socket=/var/lib/mysql/mysql.sock 


第一クラスタノードを起動する 
/etc/init.d/mysql start --wsrep-cluster-address="gcomm://" 
Starting MySQL (Percona XtraDB Cluster)...................................... SUCCESS! 

[root@node1 mysql]# cat grastate.dat 
# GALERA saved state 
version: 2.1 
uuid: 97c457f8-f3d2-11e3-9b4e-374ebb7427e6 
seqno: -1 
cert_index: 


クラスタは、現時点で唯一のノードです。 
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node1.localdomain 
1 row in set (0.01 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 1 


[OK]を今すぐ1が起動し、動作している我々は、ノード2を起動することができます 
ノード2の/ etc / my.cnfに 
[mysqld] 

datadir=/var/lib/mysql 
user=mysql 

# Path to Galera library 
wsrep_provider=/usr/lib64/libgalera_smm.so 

# Cluster connection URL contains the IPs of node#1, node#2 and node#3 
# node 1 192.168.0.33 
# nod3 2 192.168.0.34 
# nod3 3 192.168.0.35 
wsrep_cluster_address=gcomm://192.168.0.33,192.168.0.34,192.168.0.35 

# In order for Galera to work correctly binlog format should be ROW 
binlog_format=ROW 

# MyISAM storage engine has only experimental support 
default_storage_engine=InnoDB 

# This changes how InnoDB auto increment locks are managed and is a requirement for Galera 
innodb_autoinc_lock_mode=2 

# Node #1 address 
wsrep_node_address=192.168.0.34 

# SST method 
#wsrep_sst_method=xtrabackup 
wsrep_sst_method=rsync # 
# wsrep_sst_method=rsync_wan # 
# wsrep_sst_method=mysqldump # SLOW 


# Cluster name 
wsrep_cluster_name=percona_cluster 

# Authentication for SST method 
wsrep_sst_auth="root:" 

# to enable debug level logging, set this to 1 
wsrep_debug=1 

# server_id 
server_id=3232235554 # SELECT INET_ATON('192.168.0.34') 

#[client] 
socket=/var/lib/mysql/mysql.sock 

[root@node2 mysql]#/etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)........................... SUCCESS! 


今、各ノード上で私たちの値を比較します。 
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node1.localdomain 
1 row in set (0.01 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 2 

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node2.localdomain 
1 row in set (0.00 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 2 
1 row in set (0.18 sec) 


今、私たちは、ミックスにノード3を追加。 

ノード3は、/ etc / my.cnfに 
[mysqld] 

datadir=/var/lib/mysql 
user=mysql 

# Path to Galera library 
wsrep_provider=/usr/lib64/libgalera_smm.so 

# Cluster connection URL contains the IPs of node#1, node#2 and node#3 
# node 1 192.168.0.33 
# nod3 2 192.168.0.34 
# nod3 3 192.168.0.35 
wsrep_cluster_address=gcomm://192.168.0.33,192.168.0.34,192.168.0.35 

# In order for Galera to work correctly binlog format should be ROW 
binlog_format=ROW 

# MyISAM storage engine has only experimental support 
default_storage_engine=InnoDB 

# This changes how InnoDB auto increment locks are managed and is a requirement for Galera 
innodb_autoinc_lock_mode=2 

# Node #1 address 
wsrep_node_address=192.168.0.35 

# SST method 
# wsrep_sst_method=xtrabackup 
wsrep_sst_method=rsync # 
# wsrep_sst_method=rsync_wan # 
# wsrep_sst_method=mysqldump # SLOW 


# Cluster name 
wsrep_cluster_name=percona_cluster 

# Authentication for SST method 
wsrep_sst_auth="root:" 

# to enable debug level logging, set this to 1 
wsrep_debug=1 

# server_id 
server_id=3232235555 # SELECT INET_ATON('192.168.0.35') 

#[client] 
socket=/var/lib/mysql/mysql.sock 

[root@node3 mysql]#/etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)........................... SUCCESS! 

[root@node3 mysql]# cat grastate.dat 
# GALERA saved state 
version: 2.1 
uuid: 97c457f8-f3d2-11e3-9b4e-374ebb7427e6 
seqno: -1 
cert_index: 


それでは、どのよう私たちのすべてのノードは、次のようになります。 
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node1.localdomain 
1 row in set (0.01 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 3 

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node2.localdomain 
1 row in set (0.00 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 3 

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node3.localdomain 
1 row in set (0.00 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 3 

ノードをテスト 
だから今我々はいくつかのデータをロードし、それをテストすることができます.. 
[root@node2 ~]# wget http://downloads.mysql.com/docs/world_innodb.sql.gz 
[root@node2 ~]# gzip -d world_innodb.sql.gz 
[root@node2 ~]# mysql -e "create database world" 
[root@node2 ~]# mysql world < world_innodb.sql 


だから今すべてがロードされていること...それは、クラスタ全体のすべてのですか? 
@@hostname: node1.localdomain 
DATABASE_SCHEMA: world 
ENGINE: InnoDB 
count_tables: 3 
TOTAL_DB_GB: 0.001 

@@hostname: node2.localdomain 
DATABASE_SCHEMA: world 
ENGINE: InnoDB 
count_tables: 3 
TOTAL_DB_GB: 0.001 

@@hostname: node3.localdomain 
DATABASE_SCHEMA: world 
ENGINE: InnoDB 
count_tables: 3 
TOTAL_DB_GB: 0.001 

それが機能しているように見えます。