Vous êtes sur la page 1sur 14

How to Enable Remote Access To

MySQL Database Server


Here i’m going to explain, step’s to connect the mysql database remotely.

1) If you want to access mysql database remotely, you should have a Static IP so that
you can access it while adding your IP address to mysql user.
2) All Servers block port 3306 inbound request, you need to allow the port number to
particular IP on your server.

1) What is localhost ?
Localhost is a reserved address that a computer or device can use when referencing
itself.

2) What is Remote Access ?


Remote access is the ability to get access to a computer or a network from a remote
distance.

Now, i’m going to access the mysql database from MySQL Workbench from my PC
and see what will happen.
Configuration is are below:
Connection Name : 2daygeek-demo-db (Name of this connection)
Connection Method : Standard (TCP/IP)
Parameters:
Host Name : 83.170.96.101 (Server IP Address)
Port : 3306 (mysql access port)
User Name : demou (Database Name which you want to connect)
Password : ******* (store your database password)
When i access the database, i got below error message but i have given correct
required details.

3) How to show’s created database ?


Use the below command to list out the database which is created on mysql server.

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| demodb |
| demodb1 |
| 2daygeek |
| mysql |
| performance_schema |
+--------------------+
6 rows in set (0.01 sec)

4) How to shows created database users ?


Use the below command to list out the database users which is created on mysql
server.
mysql> SELECT User FROM mysql.user;
+-----------+
| User |
+-----------+
| 2daygeek |
| root |
| root |
| |
| root |
| |
| demou |
| demouser1 |
| 2daygeek |
| root |
+-----------+
10 rows in set (0.00 sec)

5) How to shows user,host privilege ?


Use the below command to check the list of host assigned to users on mysql server.

mysql> select user,host from mysql.user;


+-----------+------------------------+
| user | host |
+-----------+------------------------+
| 2daygeek | % |
| root | 127.0.0.1 |
| root | ::1 |
| | Server10001.uk2net.com |
| root | Server10001.uk2net.com |
| | localhost |
| demou | localhost |
| demouser1 | localhost |
| 2daygeek | localhost |
| root | localhost |
+-----------+------------------------+
10 rows in set (0.00 sec)

The output is clearly shows, demou user will be accessible locally(inside the server)
and not for outside (remotely). I’m going to give a remote access to my static IP. See
the below output.
6) Assigning privilege to user ?
Use the below command to enable remote access which you want.

mysql> GRANT ALL PRIVILEGES ON demodb.* TO 'demou'@'219.91.219.14';


Query OK, 0 rows affected (0.00 sec)

Whatever the permission which you assign to database you should flush the
privileges.

mysql> FLUSH PRIVILEGES;


Query OK, 0 rows affected (0.01 sec)

Now, i’m going to check whether the IP address is added or not to particular user.

mysql> select user,host from mysql.user;


+-----------+------------------------+
| user | host |
+-----------+------------------------+
| 2daygeek | % |
| root | 127.0.0.1 |
| demou | 219.91.219.14 |
| root | ::1 |
| | Server10001.uk2net.com |
| root | Server10001.uk2net.com |
| | localhost |
| demou | localhost |
| demouser1 | localhost |
| 2daygeek | localhost |
| root | localhost |
+-----------+------------------------+
11 rows in set (0.00 sec)

I’m going to access the database once again via MySQL Workbench. Now its got
successes. See the output below.
We are preparing all articles in-depth to understand by all level/stage Linux
administrators. If the article is useful for you, then please spend less than a minute to
share your valuable comments in our commenting section.

Please stay tune with us…Good Luck

How To Create a New User and


Grant Permissions in MySQL
Jun 12, 2012 MySQL

What the Red Means


The lines that the user needs to enter or customize will be in red in this tutorial! The rest
should mostly be copy-and-pastable.

About MySQL
MySQL is an open source database management software that helps users store,
organize, and later retrieve data. It has a variety of options to grant specific users
nuanced permissions within the tables and databases—this tutorial will give a short
overview of a few of the many options.

How to Create a New User


In Part 1 of the MySQL Tutorial, we did all of the editing in MySQL as the root user, with
full access to all of the databases. However, in the cases where more restrictions may
be required, there are ways to create users with custom permissions.

Let’s start by making a new user within the MySQL shell:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Sadly, at this point newuser has no permissions to do anything with the databases. In
fact, if newuser even tries to login (with the password, password), they will not be able
to reach the MySQL shell.

Therefore, the first thing to do is to provide the user with access to the information they
will need.

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

The asterisks in this command refer to the database and table (respectively) that they
can access—this specific command allows to the user to read, edit, execute and
perform all tasks across all the databases and tables.

Once you have finalized the permissions that you want to set up for your new users,
always be sure to reload all the privileges.

FLUSH PRIVILEGES;

Your changes will now be in effect.


How To Grant Different User Permissions
Here is a short list of other common possible permissions that users can enjoy.

 ALL PRIVILEGES- as we saw previously, this would allow a MySQL


user all access to a designated database (or if no database is
selected, across the system)
 CREATE- allows them to create new tables or databases
 DROP- allows them to them to delete tables or databases
 DELETE- allows them to delete rows from tables
 INSERT- allows them to insert rows into tables
 SELECT- allows them to use the Select command to read through
databases
 UPDATE- allow them to update table rows
 GRANT OPTION- allows them to grant or remove other users'
privileges
To provide a specific user with a permission, you can use this framework:

GRANT [type of permission] ON [database name].[table name] TO


‘[username]’@'localhost’;

If you want to give them access to any database or to any table, make sure to put an
asterisk (*) in the place of the database name or table name.

Each time you update or change a permission be sure to use the Flush Privileges
command.

If you need to revoke a permission, the structure is almost identical to granting it:

REVOKE [type of permission] ON [database name].[table name] FROM


‘[username]’@‘localhost’;

Just as you can delete databases with DROP, you can use DROP to delete a user
altogether:

DROP USER ‘demo’@‘localhost’;


To test out your new user, log out by typing

quit

and log back in with this command in terminal:

mysql -u [username]-p

------------
Allow Remote Ronnections Acess to MySQL Server
Posted by Nikesh Jauhari

MySQL by default allows you to connect to it via localhost, you can not connect to MySQL
server directly from some remote IP address.

To enable remote mysql access you just need to perform a little editing in the mysql
configuration file. Open the mysql configuration file -- /etc/mysql/my.cnf and look for line

bind-address = 127.0.0.1
Change the above line (Comment out) with following and save the changes

#bind-address = 127.0.0.1

Now, restart MySQL with the command:

sudo /etc/init.d/mysql restart


Now, login into mysql server (from command prompt) using root account using command:

mysql -u root -p
On successfull login, you will need to grant rights to a user so that the user has rights to perform
DB activities from some IP address other than the server where your database is hosted
(localhost).

grant all privileges on *.* to user@192.68.1.1 identified by "password";


flush privileges;
Where:
*. is the database or databases that are authorized (* means all, but you can of course just
choose one)
user is the MySQL username that you are granting remote access,
192.168.1.1 is the IP Address of the remote server that you are granting access to (this can be
replaced by * for ALL servers),
password is the password of the mysql user in question

Read more: http://linuxpoison.blogspot.in/2011/05/allow-remote-ronnections-acess-to-


mysql.html#ixzz41lZqVAen

MySQL syntax for inserting a new row in middle rows?

Good Code:
mysql sintax for insert a new row in middle rows or wherever we want without updating the
existing row, but automatically increment the primary key (id)?

' id | value
' 1 | 100
' 2 | 200
' 3 | 400
' 4 | 500
I want to insert a new row after id 2, with a value = 300. I want the output as below:

' id | value
' 1 | 100
' 2 | 200
' 3 | 300 <-- new row with id (automatic increment)
' 4 | 400 <-- id=id+1
' 5 | 500 <-- id=id+1

You will have to split it into 2 operations.

START TRANSACTION;

UPDATE table1 SET id = id + 1 WHERE id >= 3 order by id DESC;

INSERT INTO table1 (id, value) VALUES (3, 300);

COMMIT;
Notice that you need the order by in the update statement, so it will start with the highest
ids first.
Another idea would be to declare id as decimal(10,1) and insert value 2.5 as id in between
2 and 3.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Unicode from MySQL database displaying as


question marks
This is a common problem when using UTF-8.

First off, have you ensured that all of your HTML or PHP files are saved in UTF-8 format without
BOM (byte order mark)?

You also have to make sure that your server is sending a UTF-8 header in the response headers. I
think (not sure) that ASO's default setup does that, but you will want to examine your response
headers either in your browser (use Firefox Inspector if you are using Firefox) to make sure you are
or verify using a web header viewer. The response header character set declaration is much more
important than doing it in the HTML (it is a good idea to do both). If you are not sending a UTF-8
character encoding in the response header, you can do that using PHP's header() function or in
htaccess.

Set header character set using PHP header:

header('Content-Type: text/html; charset=UTF-8');

Set character set using .htaccess:

AddDefaultCharset UTF-8

Make sure your MySQL server connection collation is set to UTF-8 (I think it should be by default on
ASO). Then for every text field inside your database tables ensure the collation/chacter set is set to
UTF-8. If you have mangled text inside your database, you will have mangled output. Take a quick
look at it using phpMyAdmin and see if you have character problems. If you do, you may have to re-
import your data or find a way to convert it.
Now that we got that out of the way, make sure you run a "SET NAMES" query before you run any
other queries (not tested).

mysql_query('SET NAMES utf8')

PHP recommends using the mysql_set_charset() function to set the character set instead of a SET
NAMES query, but since you are doing things the old way it really doesn't matter.

That last step running the SET NAMES query you may want to try first if you know you are doing
everything else mentioned above.

The mysql extension has been deprecated in PHP 5.5 in favor of the "improved" mysqli
extension. You should start writing your code to use mysqli in the future.

That's about all I am aware of. There's quite a bit to do to use UTF-8 properly.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

PHP How To Sort MYSQL Fulltext Search By Relevancy


Contents

1. MySQL
2. The Old Way
3. FULL TEXT
4. Relevancy

MySQL

This tutorial assumes a basic understanding of PHP and MySQL. Please read the MySQL
tutorial.

This tutorial uses MySQL version 5.6.

The Old Way

For this tutorial, a simple table is created as follows

CREATE TABLE tutorial(


id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR(25) NOT NULL COMMENT 'The name of the tutorial',
body TEXT NOT NULL COMMENT 'The body of the tutorial'
);

Prior to MySQL version 5.6, FULL TEXT searches could only be performed on MyISAM
tables, however, with the advent of 5.6 and creater, InnoDB tables can also be searched.

In MySQL 5.6, FULL TEXT seaches may be performed on CHAR, VARCHAR, and TEXT
fields.

Previously, searches in MySQL were performed using the LIKE operator. Queries like this:

SELECT id, title, body FROM tutorials WHERE title LIKE '%keyword%' OR body LIKE '%keyword%';

Whilst this method of searching records works, several problems arise. If the keyword is too
generic, far too many results are returned. There is also no way of determining th e relevency of
the returned results, and perhaps the greatest problem, is that the query is slow as it uses string
comparisons on every record title and body. As the database grows, the query will become
slower and slower.

To alleviate this, MySQL introduced FULL TEXT searching.

FULL TEXT

Our simple table above has a unique identifier with the primary key index. For FULL TEXT
searching, a FULL TEXT INDEX needs to be applied to the fields which needs to searched.

We begin the FULL TEXT search by adding FULL TEXT indexes to the fields that will be
searched. In this case, the title and body fields.

ALTER TABLE tutorials ADD FULLTEXT( title, body );

With the FULLTEXT index in place, a query can now be created to search.

SELECT id, title, body FROM tutorials WHERE MATCH(title, body) AGAINST ('keyword')

Now the search will match the title and body fields against the text 'keyword'.

Relevancy

The above query correct retrieves the required results, however, in most instances, the top
scoring results are required.

SELECT
id, title, body, MATCH(title, body)
AGAINST ('keyword') `AS score
FROM tutorials
WHERE MATCH(title, body) AGAINST('keyword')
ORDER BY score DESC;

The search now scores each result, and returns the score ORDERed by relevancy. Enjoy

Passing Multiple Parameters in One Query String

It is nice to be able to pass a parameter in a URL query string. However, you are not limited to
one parameter per URL; you can pass a lot of them at once. You concatenate parameters using
an ampersand (&). Concatenated URL parameters in a query string look like this:

SomeActionPage.cfm?param1=value1&param2=value2&param3=value3

That should help you get a good start in working with FORM and URL variables in ColdFusion.

My new book, Core ColdFusion 5, contains a complete e-commerce site, best practices, help on
finding a ColdFusion job, and much more information on using variables in ColdFusion,
including complex data types. Pick up a copy today to find out more.

PHP read Hindi text file in unicode format


if (file_exists($SourceDirectoryFile))
{
$NameBook = "HindiFile.txt";

$contents = file_get_contents($NameBook);

// browser should display UTF-8 characters


header('Content-Type: text/html; charset=UTF-8');
echo $contents . '<hr/>';
}

Vous aimerez peut-être aussi