Thursday, June 26, 2014

MySQL的表錯誤1064

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

所以,我碰到一個奇怪的局面今天就來了。 

我有一個使用PHP $ _COOKIE ['PHPSESSID']的值創建內存表的系統。 

一旦有些工作已經完成它,然後刪除表。 

兩個示例表下面是我的榜樣。 


@@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 


現在,修復其實很簡單。 但問題是,為什麼一部作品和一個失敗? 

為了解決這個問題只是反引號的表名。 我應該從一開始無論如何都做。 這僅僅是一個良好的習慣進入。 


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


現在,我首先想到的,也許這個問題是字母數字的名稱,但我們可以看到,一個版本的作品。 所不同的不過是表名的開頭。 之一是一個整數和一個是字母字符。 如此反复..遵循最佳實踐和報價表名,以避免這種愚蠢的錯誤。 


在所有的錯誤代碼是解析錯誤.. 


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

Tuesday, June 17, 2014

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 I <= R <J2,使用表達式FLOOR(i + RAND()*(十-一)) “ 

所以,舉個例子: 

> 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 

Sunday, June 15, 2014

安裝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密鑰,並放入authorized_keys文件,這樣所有的id_rsa.pub文件值在所有服務器上的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-庫和相關的依賴任何衝突 
# 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的集群包。 
# 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運行著三個實例這還不是一個集群。 

配置節點

節點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 


現在好了現在一個是啟動並運行,我們就可以開始節點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 

看起來這是工作。