MySQL Archives - David Yin's Blog https://www.yinfor.com/tag/mysql Tech geek. Life geek. Sat, 27 Jul 2024 23:19:43 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://www.yinfor.com/wp-content/uploads/2016/09/cropped-icon-120x120.png MySQL Archives - David Yin's Blog https://www.yinfor.com/tag/mysql 32 32 Make an AQI device with Raspberry Pi Pico W and ENS160+AHT21 in 5 Steps https://www.yinfor.com/2024/07/make-an-aqi-device-with-raspberry-pi-pico-w-and-ens160aht21-in-5-steps.html https://www.yinfor.com/2024/07/make-an-aqi-device-with-raspberry-pi-pico-w-and-ens160aht21-in-5-steps.html#respond Sat, 27 Jul 2024 23:19:42 +0000 https://www.yinfor.com/?p=9836 I received the ENS160+AHT21 sensor module yesterday. I can not wait for any more for the stuff. So, I build the AQI device right away. I have to give credit to TimHanewich for his project on GitHub. I changed it...

The post Make an AQI device with Raspberry Pi Pico W and ENS160+AHT21 in 5 Steps appeared first on David Yin's Blog.

]]>
I received the ENS160+AHT21 sensor module yesterday. I can not wait for any more for the stuff. So, I build the AQI device right away.

I have to give credit to TimHanewich for his project on GitHub.

I changed it a little bit and recorded it below.

  • A data sampling and upload script, written in MicroPython, running on a Raspberry Pi Pico W.
  • An ENS160 Digital Metal Oxide Multi-Gas Sensor, is used for monitoring Carbon Dioxide (CO2), Total Volatile Organic Compounds (TOVC), and the Air Quality Index (AQI) of your home via the I2C protocol.
  • An AHT21 Integrated Temperature and Humidity Sensor is used to monitor the ambient temperature and humidity of your home via the I2C protocol.

Step 1

Get a USB cable with a Micro USB B port to connect Raspberry Pi Pico W to a PC (Windows).

Go to the MicroPython website to download the latest firmware for Pico W.  The one I download is v1.23.0.

Hold the BOOTSEL button on Pico W, then connect to the PC.

After a few seconds, the PC will find a drive. Drag the uf2 file I downloaded above to it.

Step 2

Connect the two stuff. as below.

Step 3

Download the Thonny IDE and install it on the Windows. I downloaded v4.1.4.

Step 4

Prepare the code. The Code I updated can be downloaded here. src

Four files.

Edit settings.py to add the WiFI information and the post_url.  You can change the sample_time to 300 for measuring every five minutes.

In the main.py, I changed line 27 to match the wiring above.

Step 5

Connect the Pico W with the PC.

Launch Thonny IDE. Click Run > Interpreter, and select MicroPyton (Raspberry Pi Pico). click OK.

 

Then, open the files one by one and save a copy to the device.

Select the main.py file. Then click the Green Play button.

I post the data to a php file to save it to the MySQL database.

The 4th item with high eco2 and tvoc, because I opened the bottle of Alcool isophopylique.

Here is what it looks like for the setup. I mounted them on a 2X4 block with screws. I can move it anywhere in the house. I can also use the battery to power it.

Option:

The database structure of database aqi_1

The setting of the URL in settings.py.

post_url:str = "https://gthree.win/tools/aqi-data.php"

The main part of  aqi-data.php is as follows:

 
$data = json_decode(file_get_contents('php://input'));

$humidity = $data->{'humidity'};
$temperature = $data->{'temperature'};
$eco2 = $data->{'eco2'};
$aqi = $data->{'aqi'};
$tvoc = $data->{'tvoc'};
 
// Database connection 
$conn = new mysqli('localhost', 'username', 'password', 'aqi_1'); 
 
// Insert data Query 
$sql = "INSERT INTO env_status ( humidity, temperature, eco2, aqi, tvoc) 
VALUES ($humidity, $temperature, $eco2, $aqi, $tvoc)"; 
 
if ($conn->query($sql) === TRUE) { 
  echo "Insert your JSON record successfully"; 
}

Received the data and saved them to the database.

The post Make an AQI device with Raspberry Pi Pico W and ENS160+AHT21 in 5 Steps appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2024/07/make-an-aqi-device-with-raspberry-pi-pico-w-and-ens160aht21-in-5-steps.html/feed/ 0
Increase Max Connections in MySQL https://www.yinfor.com/2022/03/increase-max-connections-in-mysql.html https://www.yinfor.com/2022/03/increase-max-connections-in-mysql.html#respond Tue, 08 Mar 2022 00:45:21 +0000 https://www.yinfor.com/?p=8051 Recently, my VPS which hosted a bunch of WordPress sites gave an error message: Too many connections. I mean all available connections have been used by the various clients and my MySQL server can not serve any new connections until...

The post Increase Max Connections in MySQL appeared first on David Yin's Blog.

]]>
Recently, my VPS which hosted a bunch of WordPress sites gave an error message: Too many connections. I mean all available connections have been used by the various clients and my MySQL server can not serve any new connections until any of the existing connections is closed.

How Many Connections Can MySQL handle?

The default, MariaDB 10.3.34 can handle up to 151 connections. The number is stored in a server variable called max_connections.

How to Increase Max Connection in MySQL?

Check the default max connections

The main command  is:

show variables like "max_connections";

The output is 151.

Increase Max Connections in settings

The file keeps the setting of max_connections is located /etc/mysql/mariadb.conf.d/  the file name is 50-server.cnf

cd /etc/mysql/mariadb.conf.d

sudo nano 50-server.cnf

Find the line of max_connections , remove the comment characters or just just add the following in to the end of the file, save it.

max_connections = 200

Restart MySQL server

sudo service mariadb restart

Then, try to check the max connections variable by the previous way mentioned above, the result is 200.

The post Increase Max Connections in MySQL appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2022/03/increase-max-connections-in-mysql.html/feed/ 0
Hot to fix the problem on the new installation MariaDB https://www.yinfor.com/2019/03/hot-to-fix-the-problem-on-the-new-installation-mariadb.html https://www.yinfor.com/2019/03/hot-to-fix-the-problem-on-the-new-installation-mariadb.html#comments Fri, 29 Mar 2019 21:05:49 +0000 https://www.yinfor.com/?p=6802 After the installation of MySQL server or MariaDB on Ubuntu, I would like to use phpMyAdmin or Adminer to access the MySQL server. But the first time the error comes like below. Access denied for user ‘root’@’localhost’ mysqli_real_connect(): (HY000/1698): Access...

The post Hot to fix the problem on the new installation MariaDB appeared first on David Yin's Blog.

]]>
After the installation of MySQL server or MariaDB on Ubuntu, I would like to use phpMyAdmin or Adminer to access the MySQL server. But the first time the error comes like below.

Access denied for user ‘root’@’localhost’

mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’localhost’

MySQL connect error on phpMyAdmin

 

MySQL connect error on Adminer

Here is the solution to make the root connect to a server without error.

First SSH to the terminal window of the Ubuntu 18.04.

Run the following command to check the MySQL root user’s information.

davidyin@example:~$ sudo mysql -uroot -p
[sudo] password for davidyin:
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 169
Server version: 10.1.38-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> SELECT User, Host, plugin FROM mysql.user;
+——+———–+————-+
| User | Host | plugin |
+——+———–+————-+
| root | localhost | unix_socket |
+——+———–+————-+
1 row in set (0.00 sec)

MySQL root user plugin

I saw the root user is using unix_socket. I will change it to mysql native password.

MariaDB [(none)]> UPDATE mysql.user SET plugin=’mysql_native_password’ WHERE User=’root’;
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.08 sec)

MariaDB [(none)]> exit;
Bye

Update MySQL root user auth method

 

Now, at this step, I can access Adminer and phpMyAdmin without any problems.

Another workaround I found by Google. Someone creates a new MySQL user and give the superuser permission to it.  Then use this superuser to access MySQL server.

The post Hot to fix the problem on the new installation MariaDB appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2019/03/hot-to-fix-the-problem-on-the-new-installation-mariadb.html/feed/ 1
Use Adminer to manage the MySQL database https://www.yinfor.com/2019/03/use-adminer-to-manage-the-mysql-database.html https://www.yinfor.com/2019/03/use-adminer-to-manage-the-mysql-database.html#respond Thu, 28 Mar 2019 08:12:46 +0000 https://www.yinfor.com/?p=6800 I am used to using phpmyadmin to manage the MySQL database for many years. Just recently, I saw an alternative way to do it. Adminer,  a full-featured database management tool written in PHP. The latest version is v4.7.1 when I...

The post Use Adminer to manage the MySQL database appeared first on David Yin's Blog.

]]>
I am used to using phpmyadmin to manage the MySQL database for many years. Just recently, I saw an alternative way to do it. Adminer,  a full-featured database management tool written in PHP.

Official site of Adminer

The latest version is v4.7.1 when I write this post.

Features

  • Connect to a database server with username and password
  • Select an existing database or create a new one
  • List fields, indexes, foreign keys and triggers of table
  • Change name, engine, collation, auto_increment and comment of table
  • Alter name, type, collation, comment and default values of columns
  • Add and drop tables and columns
  • Create, alter, drop and search by indexes including fulltext
  • Create, alter, drop and link lists by foreign keys
  • Create, alter, drop and select from views
  • Create, alter, drop and call stored procedures and functions
  • Create, alter and drop triggers
  • List data in tables with search, aggregate, sort and limit results
  • Insert new records, update and delete the existing ones
  • Supports all data types, blobs through file transfer
  • Execute any SQL command from a text field or a file
  • Export table structure, data, views, routines, databases to SQL or CSV
  • Print database schema connected by foreign keys
  • Show processes and kill them
  • Display users and rights and change them
  • Display variables with links to documentation
  • Manage events and table partitions (MySQL 5.1)
  • Schemas, sequences, user types (PostgreSQL)
  • Extensive customization options

It is a single file program. Include multiple language. You can download it from the official site here.

The post Use Adminer to manage the MySQL database appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2019/03/use-adminer-to-manage-the-mysql-database.html/feed/ 0
HHVM 3.6 has problem with MariaDB https://www.yinfor.com/2015/03/hhvm-3-6-has-problem-with-mariadb.html https://www.yinfor.com/2015/03/hhvm-3-6-has-problem-with-mariadb.html#respond Wed, 18 Mar 2015 06:13:10 +0000 https://www.yinfor.com/?p=4190 The same script php file, always works smoothly on HHVM 3.2 to HHVM 3.5. Until I upgrade it to HHVM 3.6. It is a simply script which use mysqli connection and so on. Now it is shown the error as...

The post HHVM 3.6 has problem with MariaDB appeared first on David Yin's Blog.

]]>
The same script php file, always works smoothly on HHVM 3.2 to HHVM 3.5. Until I upgrade it to HHVM 3.6.

It is a simply script which use mysqli connection and so on. Now it is shown the error as below:

Connect failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I tried to find the answer and faild. So I upgrde the HHVM to nightly build version. It is 3.7-dev.

davidyin@fiob:/etc/hhvm$ hhvm --version
HipHop VM 3.7.0-dev (rel)
Compiler: heads/master-0-g0359d4a4bbb22c5defd7eb024194aed0af24c80b
Repo schema: 9008d5e6e7f6584d09ed3b14deceac5a34f363c1

And it did solve the error, and the script is working as expected.

But, later I found the reason why it happen.

Add

hhvm.mysql.socket = /tmp/mysql.sock

into server.ini

To specify the mysql socket and let HHVM knows how to connect mySQL server or MariaDB server.

I did not try the solution.  I found it here.

The post HHVM 3.6 has problem with MariaDB appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2015/03/hhvm-3-6-has-problem-with-mariadb.html/feed/ 0
Switch to bzip2 compression on my server backup scripts https://www.yinfor.com/2015/02/switch-bzip2-compression-server-backup-scripts.html https://www.yinfor.com/2015/02/switch-bzip2-compression-server-backup-scripts.html#respond Tue, 10 Feb 2015 02:33:27 +0000 https://www.yinfor.com/?p=4135 Previously I used gzip as compression tool to compress the web site files and mysql database.  It is still working on my Linode server. I learned something from the compairasion from this post . So I tried to use bzip...

The post Switch to bzip2 compression on my server backup scripts appeared first on David Yin's Blog.

]]>
Previously I used gzip as compression tool to compress the web site files and mysql database.  It is still working on my Linode server. I learned something from the compairasion from this post .

So I tried to use bzip instead of gzip on my backup script.

Here is two examples.

1) Mysqldump file, which is a text sql file.

The original sql file is 52,317KB

  • gzip with level 9 (best) compression:  23,227KB  – Compress Ratio 44.39%
  • bzip2 with default (I think it is level 9) compression: 19,666KB – Compress Ratio 37.59%

Bzip2 is smaller than gzip file. It reduced about 15%.

2) Website files, including php, jpeg, png, css, any files used in web site.

The original tar gile is 187,670KB

  • gzip compression: 42,101KB – Ratio 22.43%
  • bzip2 compression: 34,753KB – Ratio 18.51%

Bzip2 is better. Backup file size is reduced by about 17%.

The following screenshot is the second example.

bz2-vs-gz

  • sites.tar is the original file.
  • sites.tar.gz is compressed by gzip.
  • sites.bz2 is compressed by bzip2.

Because I am using it as a backup tool, the space occuppied is very important. To save the disk space, I chose bzip2 to replace gzip.

 

So my mysql database backup script is changed as below:


#!/bin/bash
### MySQL Server Login Info ###
MUSER="MySQL User name"
MPASS="MySQL Pass"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BAK="/home/usera/backup/mysql"
GZIP="$(which gzip)"
BZIP2="$(which bzip2)"
### FTP SERVER Login info ###
FTPU="FTP User name"
FTPP="FTP Pass"
FTPS="backup.dreamhost.com"
NOW=$(date +"%d-%m-%Y")
[ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/*
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BAK/$db.$NOW-$(date +"%T").gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $BZIP2> $FILE
done
lftp -u $FTPU,$FTPP -e "mkdir /vps/backup/mysql/$NOW;cd /vps/backup/mysql/$NOW; mput /home/usera/backup/mysql/*; quit" $FTPS
find /home/usera/backup/mysql -ctime +4 -exec rm {} \;

 

 

The post Switch to bzip2 compression on my server backup scripts appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2015/02/switch-bzip2-compression-server-backup-scripts.html/feed/ 0
How to manage MariaDB in Webmin https://www.yinfor.com/2014/04/how-to-manage-mariadb-in-webmin.html https://www.yinfor.com/2014/04/how-to-manage-mariadb-in-webmin.html#comments Thu, 01 May 2014 00:38:28 +0000 https://www.yinfor.com/?p=3658 It is easy to use Webmin to manage VPS, including MySQL server.  But it is not working with MariaDB default. The webmin MySQL server shows error as below: It can not find the path of command to start and stop...

The post How to manage MariaDB in Webmin appeared first on David Yin's Blog.

]]>
It is easy to use Webmin to manage VPS, including MySQL server.  But it is not working with MariaDB default.

The webmin MySQL server shows error as below:

mariadb-webmin

It can not find the path of command to start and stop MariaDB and also config file of MariaDB server.

So click module configuration and change:
Command to start MySQL server: /etc/init.d/mysql start
Command to stop MySQL server: /etc/init.d/mysql stop
MySQL configuration file: /var/lib/mysql/my.cnf

If your MariaDB server configuration file is not in this location, double check your setting and enter the correct value.

After saving, it will ask for your username and password to connect your MariaDB server.  Enter them and save.

mariadb-settings

At this step, you can add database or do other tasks in Webmin.

The post How to manage MariaDB in Webmin appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2014/04/how-to-manage-mariadb-in-webmin.html/feed/ 1
Convert MyISAM tables to InnoDB without Touching Data https://www.yinfor.com/2014/02/convert-myisam-tables-to-innodb-without-touching-data.html https://www.yinfor.com/2014/02/convert-myisam-tables-to-innodb-without-touching-data.html#respond Wed, 26 Feb 2014 02:18:06 +0000 https://www.yinfor.com/?p=3414 It is a smoothly converting without hurting data inside of the tables. I have phpmyadmin installation on my VPS. So just goto there and select database, click SQL tab of it. Enter following sql and click Go. ALTER TABLE tablename...

The post Convert MyISAM tables to InnoDB without Touching Data appeared first on David Yin's Blog.

]]>
It is a smoothly converting without hurting data inside of the tables.

I have phpmyadmin installation on my VPS. So just goto there and select database, click SQL tab of it.

Enter following sql and click Go.

ALTER TABLE tablename ENGINE = INNODB;

alter-tables-engine

If the table is large, then it may take a while to convert it over. There will probably be a fair amount of CPU usage and disk I/O in the process. In my case, I do not feel the delay when I click Go button.

There are also some script can help you alter all tables. Then, you don’t have to type sql command for each table, if you have hundred tables of databases.

<?php
    // connect your database here first
    //

    // Actual code starts here

    $sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine <> 'InnoDB'";
    $rs = mysql_query($sql);

    while($row = mysql_fetch_array($rs))
    {
        $tbl = $row[0];
        $sql = "ALTER TABLE $tbl ENGINE=INNODB";
        mysql_query($sql);
    }
?>

Save above php script into a php file into your web server. Modify the database connection portion. Then run this script from your browser. It will do all the job for you.

Some help from Major.

The post Convert MyISAM tables to InnoDB without Touching Data appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2014/02/convert-myisam-tables-to-innodb-without-touching-data.html/feed/ 0
Another MySQL daemon already running with the same unix socket https://www.yinfor.com/2014/02/another-mysql-daemon-already-running-with-the-same-unix-socket.html https://www.yinfor.com/2014/02/another-mysql-daemon-already-running-with-the-same-unix-socket.html#respond Mon, 03 Feb 2014 22:26:10 +0000 https://www.yinfor.com/?p=1537 The error when I try to start MySQL server in the VPS. Another MySQL daemon already running with the same unix socket I googled it and found the solution. Since I am working on CentOS, enter the following command in...

The post Another MySQL daemon already running with the same unix socket appeared first on David Yin's Blog.

]]>
The error when I try to start MySQL server in the VPS.

Another MySQL daemon already running with the same unix socket

I googled it and found the solution.

mysql-error

Since I am working on CentOS, enter the following command in console

service mysqld stop
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld start

I think the problem is due to hard power off. The server is not shutdown properly. So the mysql.sock is not deleted on rebooting.

The post Another MySQL daemon already running with the same unix socket appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2014/02/another-mysql-daemon-already-running-with-the-same-unix-socket.html/feed/ 0
bc not found error when running Mysql tuning primer script https://www.yinfor.com/2013/10/bc-not-found-error-when-running-mysql-tuning-primer-script.html https://www.yinfor.com/2013/10/bc-not-found-error-when-running-mysql-tuning-primer-script.html#respond Mon, 28 Oct 2013 03:55:49 +0000 https://www.yinfor.com/?p=1354 To fine tuning mysql server, run Mysql tuning primer script on server. But I got error which said bc is not found. So just enter following yum install bc to install it. [root@vps test]# ./tuning-primer.sh which: no bc in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)...

The post bc not found error when running Mysql tuning primer script appeared first on David Yin's Blog.

]]>
To fine tuning mysql server, run Mysql tuning primer script on server.

But I got error which said bc is not found. So just enter following yum install bc to install it.

[root@vps test]# ./tuning-primer.sh
which: no bc in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
Error: Command line calculator 'bc' not found!
[root@vps test]# yum install bc

The post bc not found error when running Mysql tuning primer script appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2013/10/bc-not-found-error-when-running-mysql-tuning-primer-script.html/feed/ 0
Install LEMP on Centos 6.4 64bit at Burst.Net VPS https://www.yinfor.com/2013/10/install-lemp-on-centos-at-burst-net-vps.html https://www.yinfor.com/2013/10/install-lemp-on-centos-at-burst-net-vps.html#respond Tue, 22 Oct 2013 23:34:45 +0000 https://www.yinfor.com/?p=1292 It is a guide to install LEMP on a Centos 6.4 64bit VPS at Burst.net. It is also working on other VPS. LEMP stands for Linux, NginX, MySQL, PHP. First of all, rebuild the OS on VPS with Centos-6.2-x86_64. Other...

The post Install LEMP on Centos 6.4 64bit at Burst.Net VPS appeared first on David Yin's Blog.

]]>
It is a guide to install LEMP on a Centos 6.4 64bit VPS at Burst.net. It is also working on other VPS. LEMP stands for Linux, NginX, MySQL, PHP.

First of all, rebuild the OS on VPS with Centos-6.2-x86_64.
os-load

Other VPS providers have similar interface to rebuild / reload operation system.

After 5 to 10 minutes, the VPS is ready to use.

SSH to VPS through PUTTY with root account.  The following installation steps will be done in terminal window.

1) Update the system to Centos 6.4

yum update

There are 158 updates need to be installed. So just confirm it and wait all the updates completed. Then the Centos is updated from 6.2 to 6.4.

2) Install the required repositories

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

3) Install MySQL server

yum install mysql mysql-server

Start MySQL

/etc/init.d/mysqld restart

Configure MySQL server

/usr/bin/mysql_secure_installation

It will guide you the whole procedure of steps to make the MySQL more security. It includes adding root password, remove sample database, remove anonymous user, disable root login remotely.

4) Install NginX

yum install nginx

Start nginx

/etc/init.d/nginx start

Check the IP address

ifconfig eth0 | grep inet | awk '{ print $2 }'

or

ifconfig venet0:0 | grep inet | awk '{ print $2 }'

5) Install PHP

The php-fpm package is located within the REMI repository, which, at this point, is disabled. The first thing we need to do is enable the REMI repository and install php and php-fpm:

yum --enablerepo=remi install php-fpm php-mysql

6) Configure PHP

vi /etc/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.

cgi.fix_pathinfo=0

7) Configure Nginx

vi /etc/nginx/nginx.conf

Raise the number of worker processes to 4 then save and exit that file. Actually, my Burst.net VPS has one core only.

Now we should configure the nginx virtual hosts. In order to make the default nginx file more concise, the virtual host details are in a different location.

vi /etc/nginx/conf.d/default.conf

The configuration should be including following things. Make sure the server_name is changed to your domain or IP address.


#
# The default server
#
server {
listen       80 default_server;
server_name sample.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
root   /usr/share/nginx/html;
index  index.php index.html index.htm;
}

error_page  404              /404.html;
location = /404.html {
root   /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root           /usr/share/nginx/html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

Configure php-fpm configuration

vi /etc/php-fpm.d/www.conf

Replace apache by nginx

[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;	will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[...]

Restart php-fmp

 service php-fpm restart

8) Add autostart services

sudo chkconfig --levels 235 mysqld on
sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on

8) Make a testing page with phpinfo() function and look at the following screenshots
NginX default page
nginx
PHP information page
php-nginx

There is one issue I have during installation. When I restart nginx, following error message shown:

 * Restarting nginx
 * Stopping nginx nginx
   ...done.
 * Starting nginx nginx
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
   ...done.
   ...done.

After do a little bit research, I found it is because of the port 80 is used by others. So I found it is Apache, another web server is running already.
I enter the command to remove Apache

yum remove httpd

The post Install LEMP on Centos 6.4 64bit at Burst.Net VPS appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2013/10/install-lemp-on-centos-at-burst-net-vps.html/feed/ 0
How to install Apache2 With PHP5 And MySQL On CentOS 6.3 https://www.yinfor.com/2012/09/how_to_install_apache2_with_ph.html https://www.yinfor.com/2012/09/how_to_install_apache2_with_ph.html#respond Wed, 19 Sep 2012 22:48:40 +0000 https://www.yinfor.com/?p=1042 Before install Apache2, PHP5 and MySQL, install CentOS 6.3 server first. Followed the steps to install these staff. 1) Installing MySQL 5 yum install mysql mysql-server Then we create the system startup links for MySQL (so that MySQL starts automatically...

The post How to install Apache2 With PHP5 And MySQL On CentOS 6.3 appeared first on David Yin's Blog.

]]>
Before install Apache2, PHP5 and MySQL, install CentOS 6.3 server first.
Followed the steps to install these staff.
1) Installing MySQL 5

yum install mysql mysql-server

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

Set passwords for the MySQL root account:

mysql_secure_installation

Follow the prompt to add password to root.
2) Installing Apache2

yum install httpd

Now configure your system to start Apache at boot time…

chkconfig --levels 235 httpd on

… and start Apache:

/etc/init.d/httpd start

3) Installing PHP5
We can install PHP5 and the Apache PHP5 module as follows:

yum install php

We must restart Apache afterwards:

/etc/init.d/httpd restart

4) Getting MySQL Support In PHP5
To get MySQL support in PHP, we can install the php-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications.

yum install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc

Now restart Apache2:

/etc/init.d/httpd restart

Now, LAMP is ready to use.

The post How to install Apache2 With PHP5 And MySQL On CentOS 6.3 appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2012/09/how_to_install_apache2_with_ph.html/feed/ 0
How to solve mysqldump 1044 error https://www.yinfor.com/2012/08/how_to_solve_mysqldump_1044_er.html https://www.yinfor.com/2012/08/how_to_solve_mysqldump_1044_er.html#respond Tue, 28 Aug 2012 11:50:57 +0000 https://www.yinfor.com/?p=1016 I do a database backup very ofter with mysqldump command. Just found an error come when I run the command, mysqldump as below. mysqldump: Got error: 1044: Access denied for user ‘root’@’localhost’ to database ‘information_schema’ when using LOCK TABLES I...

The post How to solve mysqldump 1044 error appeared first on David Yin's Blog.

]]>
I do a database backup very ofter with mysqldump command.
Just found an error come when I run the command, mysqldump as below.

mysqldump: Got error: 1044: Access denied for user ‘root’@’localhost’ to database ‘information_schema’ when using LOCK TABLES

I google it and found one solution for it.


Add –single-transaction

$ mysqldump --single-transaction -u user -p DBNAME &gt; backup.sql

The post How to solve mysqldump 1044 error appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2012/08/how_to_solve_mysqldump_1044_er.html/feed/ 0
Solved MySQL 5 – Incorrect integer value: ” for column ‘id’ at row 1 https://www.yinfor.com/2012/02/solved_mysql_5_-_incorrect_int.html https://www.yinfor.com/2012/02/solved_mysql_5_-_incorrect_int.html#comments Tue, 21 Feb 2012 15:49:17 +0000 https://www.yinfor.com/?p=952 I move one site to a new server with Windows 2003. It is a MySQL database. I use PHP script to connect the database file and query it. I run the same script more than 5 years on the old...

The post Solved MySQL 5 – Incorrect integer value: ” for column ‘id’ at row 1 appeared first on David Yin's Blog.

]]>
I move one site to a new server with Windows 2003.
It is a MySQL database. I use PHP script to connect the database file and query it.
I run the same script more than 5 years on the old server. After I move it to new one, it gives me the error as subject.
I did a lot of Googling. Found the answer at this blog(the link is not working any more), but now it is not available. So, I quoted the most important part from the Google Cached page.

This is an sql-mode issue, the mode defines what SQL syntax should be supported and what kind of data validation should be performed. In my problem MySQL is trying to assign an empty string to an auto-increment INT field and, as we should all know, strings into INTs don’t go. Cue errors and the script dies.
Longer term I am going to have to re-work my code to fix this issue, but in the short term, I am going to reduce the sensitivity of the control. To lower the level of data validation we can set the sql-mode to a lower level or comment it out altogether.

Solution is below:
Edit the my.cnf (my.ini in windows) file and find and comment out the line:
#sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”

With this line commented out, STRICT mode is no longer applied and MySQL should now insert adjusted values for invalid or missing values and more specifically, it should allow my empty string to be put into the int column.

I follow this solution and everything is OK for MySQL installation.

The post Solved MySQL 5 – Incorrect integer value: ” for column ‘id’ at row 1 appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2012/02/solved_mysql_5_-_incorrect_int.html/feed/ 6
How to add one string to all rows of one column https://www.yinfor.com/2011/01/how_to_add_string_to_all_rows_.html https://www.yinfor.com/2011/01/how_to_add_string_to_all_rows_.html#respond Sat, 22 Jan 2011 00:42:51 +0000 https://www.yinfor.com/?p=876 I have a MySQL database. There is one table has thousands rows of data. I need to add one string to every rows of one column. It is a very popular scenario. Looks like in the middle of using one...

The post How to add one string to all rows of one column appeared first on David Yin's Blog.

]]>
I have a MySQL database. There is one table has thousands rows of data. I need to add one string to every rows of one column.

It is a very popular scenario. Looks like in the middle of using one database, the developer need a new column with a default value in it.

Yes, he can setup a default value, but what about the existing data. The answer is shown below.

sample_table

+------+------+--------------+
| fieldA |  fieldB        |  fieldC | 
|  22    |  star          |     2   |
|  23    |  super         |     2   | 
|  24    |  savemore      |     1   |
|  25    |  justtolook    |     4   |
|  26    |  bestbook      |     4   |

I add this string to all rows of fieldB, just after the existing data.

The SQL script is used to do this job shown as below

update sample_table set fieldB  = concat(fieldB ,'.html');

Then after this script.

+------+------+--------------+
| fieldA | fieldB                 | fieldC |
| 22      | star.html            | 2 |
| 23      | super.html         | 2 |
| 24      | savemore.html  | 1 |
| 25      | justtolook.html   | 4 |
| 26      | bestbook.html    | 4 |

The post How to add one string to all rows of one column appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2011/01/how_to_add_string_to_all_rows_.html/feed/ 0