free -m
Check if and how swap is used
Monday, March 30, 2015
Wednesday, July 30, 2014
set mysqldump to utf8
Have you tried adding
SET NAMES 'utf8';
to your sql dump?
The thing with utf8 or encodings in general is that in order to be successfull, you have to make sure that:
- the file is encoded utf8 without signature
- the default encoding of the mysql server is set to utf8
- the connection is utf8 (that's why you put SET NAMES 'utf8' into your sql-file).
- all tables and columns have the right encoding and charset
- all your webfiles have to be utf8 encoded as well. And it doesn't work to just add the correct header. You have to open the file, check if the encoding is utf8, if not, cut everything, change the encoding to utf8 and paste everything back. It doesn't work, if you just change the encoding and save the file!
Wednesday, July 23, 2014
How Do I Enable Remote Access To MySQL Database Server?
How Do I Enable Remote Access To MySQL Database Server?
Task: MySQL Server Remote Access
You need type the following commands which will allow remote connections.Step # 1: Login Using SSH (if server is outside your data center)
First, login over ssh to remote MySQL database server. You may need to login to your MySQL server as the root user:ssh user@server1.cyberciti.biz ### login as the root using su or sudo ## su #sudo -sOR directly login as root user:
ssh root@server1.cyberciti.biz
Step # 2: Edit the my.cnf file
Once connected you need to edit the MySQL server configuration file my.cnf using a text editor such as vi:- If you are using Debian Linux file is located at /etc/mysql/my.cnf location.
- If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnf location.
- If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf location.
# vi /etc/my.cnfStep # 3: Once file opened, locate line that read as follows
[mysqld]Make sure line skip-networking is commented (or remove line) and add following line
bind-address=YOUR-SERVER-IPFor example, if your MySQL server IP is 65.55.55.2 then entire block should be look like as follows:
[mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp language = /usr/share/mysql/English bind-address = 65.55.55.2 # skip-networking .... .. ....Where,
- bind-address: IP address to bind to.
- skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state.
Step# 4 Save and Close the file
If you are using Debian / Ubuntu Linux, type the following command to restart the mysql server:# /etc/init.d/mysql restartIf you are using RHEL / CentOS / Fedora / Scientific Linux, type the following command to restart the mysql server:
# /etc/init.d/mysqld restartIf you are using FreeBSD, type the following command to restart the mysql server:
# /usr/local/etc/rc.d/mysql-server stop
# /usr/local/etc/rc.d/mysql-server startOR
# /usr/local/etc/rc.d/mysql-server restartStep # 5 Grant access to remote IP address
Connect to mysql server:$ mysql -u root -p mysqlGrant access to a new database
If you want to add a new database called foo for user bar and remote IP 202.54.10.20 then you need to type the following commands at mysql> prompt:mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO bar@'202.54.10.20' IDENTIFIED BY 'PASSWORD';How Do I Grant Access To An Existing Database?
Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:mysql> update db set Host='202.54.10.20' where Db='webdb';
mysql> update user set Host='202.54.10.20' where user='webadmin';Step # 6: Logout of MySQL
Type exit command to logout mysql:mysql> exitStep # 7: Open port 3306
You need to open TCP port 3306 using iptables or BSD pf firewall.A sample iptables rule to open Linux iptables firewall
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPTOR only allow remote connection from your web server located at 10.5.1.3:
/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPTOR only allow remote connection from your lan subnet 192.168.1.0/24:
/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --destination-port 3306 -j ACCEPTFinally save all rules (RHEL / CentOS specific command):
# service iptables saveA sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf)
pass in on $ext_if proto tcp from any to any port 3306OR allow only access from your web server located at 10.5.1.3:
pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306 flags S/SA synproxy state
Step # 8: Test it
From your remote system or your desktop type the following command:$ mysql -u webadmin –h 65.55.55.2 –pWhere,
- -u webadmin: webadmin is MySQL username
- -h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN)
- -p : Prompt for password
$ echo X | telnet -e X 65.55.55.2 3306OR
$ nc -z -w1 65.55.55.2 3306Sample outputs:
Connection to 65.55.55.2 3306 port [tcp/mysql] succeeded!
Saturday, July 12, 2014
create and last update timestamp fields on mysql
As of MySQL 5.6 its easy-peasy... give it a try:
create table tweet (
id integer not null auto_increment primary key,
stamp_created timestamp default now(),
stamp_updated timestamp default now() on update now(),
message varchar(163)
)
or
`inserted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`insert_src_ver_id` INT NULL,
`updated` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP,
`update_src_ver_id` INT NULL,
for MySQL 5.5 or older
First define them like this:CREATE TABLE `entity` (
`entityid` int(11) NOT NULL AUTO_INCREMENT,
`createDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastModified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`name` varchar(255) DEFAULT NULL,
`comment` text,
PRIMARY KEY (`entityid`),
)
Then add these triggers:DELIMITER ;;
CREATE trigger entityinsert BEFORE INSERT ON entity FOR EACH ROW BEGIN SET NEW.createDate=IF(ISNULL(NEW.createDate) OR NEW.createDate='0000-00-00 00:00:00', CURRENT_TIMESTAMP, IF(NEW.createDate<CURRENT_TIMESTAMP, NEW.createDate, CURRENT_TIMESTAMP));SET NEW.lastModified=NEW.createDate; END;;
DELIMITER ;
CREATE trigger entityupdate BEFORE UPDATE ON entity FOR EACH ROW SET NEW.lastModified=IF(NEW.lastModified<OLD.lastModified, OLD.lastModified, CURRENT_TIMESTAMP);
- If you insert without specifying createDate or lastModified, they will be equal and set to the current timestamp.
- If you update them without specifying createDate or lastModified, the lastModified will be set to the current timestamp.
- If you insert, you can specify a createDate older than the current timestamp, allowing imports from older times to work well (lastModified will be equal to createDate).
- If you update, you can specify a lastModified older than the previous value ('0000-00-00 00:00:00' works well), allowing to update an entry if you're doing cosmetic changes (fixing a typo in a comment) and you want to keep the old lastModified date. This will not modify the lastModified date.
Friday, July 11, 2014
วิธีแก้ MySQL ใน Ubuntu Linux ให้รองรับภาษาไทยได้
ต้องแก้ /etc/my.cnf โดยเพิ่มตามข้างล่างนี้
To set the default to UTF-8, you want to add the following to my.cnf
To set the default to UTF-8, you want to add the following to my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Monday, May 5, 2014
How to install Gnome on Debian 6 minimally
Install Debian 6 from installation CD
Choose only Standard System Utilities. Uncheck Graphical Desktop Environment
Reboot and logon after installation finish
apt-get install xserver-xorg-input-kbd xserver-xorg-input-vmmouse xserver-xorg-video-vmware
Choose only Standard System Utilities. Uncheck Graphical Desktop Environment
Reboot and logon after installation finish
apt-get install xserver-xorg-input-kbd xserver-xorg-input-vmmouse xserver-xorg-video-vmware
Use virtualenv to manage multiple version of python on linux
virtualenv can switch between multiple python version and addon.
Use pip to install additional python packages in each python environment
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install package-name
Subscribe to:
Posts (Atom)