Page 236 - Open Soource Technologies 304.indd
P. 236

Unit 14: Connecting to MySQL with PHP



                            mysql> GRANT ALL PRIVILEGES ON *.* TO  name1@”%” IDENTIFIED  BY       Notes
                          ‘pass’ WITH GRANT OPTION;
            The above commands will provide the user “name1” with superuser permissions. The user can connect
            from anywhere.
            If you give a grant for a users that doesn’t exists, that user is created.

            After getting the user_name, password you can connect to the database server.

            To connect to the server invoke the mysql program from your shell prompt.
            Syntax of the command is:

            % mysql <options>

            % indicates the shell prompts
            mysql is the client program

            <options> include the following:

             -h host_name -u user_name -p password
             -u user_name -p (if host is localhost)

            In our example, we have the following information:
               •    host :localhost

               •  user_name :subu

               •  password :subu
               •  database :sample_db

            Given the above, to connect to the database server use the command:
            [anand soft@localhost anandsoft]$ mysql -u subu -p

            Then enter your password subu at the password prompt.

            The following screenshot depicts the above example:














            Now you are connected to the database server.
            The connection can be terminated by giving QUIT at the mysql prompt.

            mysql>QUIT

            Bye


                                             LOVELY PROFESSIONAL UNIVERSITY                                   231
   231   232   233   234   235   236   237   238   239   240   241