Cloud Hosting Applications - Using MySQL
Posted by Cinu Varghese on 24 September 2010 11:24 AM
|
|
Applicable Plans - eApps Cloud Hosting Plans (eApps templates only)User Guide - Using MySQLOverview“MySQL is a relational database management system (RDBMS) that has more than 6 million installations. MySQL stands for “My Structured Query Language”. The program runs as a server providing multi-user access to a number of databases…MySQL is often used in free software projects that require a full-featured database management system, such as WordPress, phpBB and other software built on the LAMP software stack. It is also used in very high-scale World Wide Web products including Wikipedia, Google and Facebook” – from http://en.wikipedia.org/wiki/MySQL The eApps Cloud Hosting service is designed to make it easy to use MySQL in your Virtual Machine. This User Guide is not intended as a reference source for MySQL. See the Links to other information at the end of this document if you need detailed information about MySQL. Installing MySQL Creating databases and database users Creating a database and user from the Command Line Importing content to a MySQL database Stopping and starting MySQL MySQL Configuration Backing up MySQL Databases Installing MySQL and setting the MySQL root passwordInstalling MySQL from the Control PanelMySQL is installed from the Applications section of the Control Panel. See the User Guide - Installing and Managing Applications http://support.eapps.com/control_panel_eapps/app_manager for more information if needed. Along with MySQL, you may also want to install phpMyAdmin, which provides a browser-based interface to manage MySQL databases. Changing the root MySQL passwordThe first thing to do after MySQL is installed is to set the root MySQL password. When MySQL is installed, no root MySQL password is created. A password needs to be created of your choosing for security reasons. Keep in mind that the root MySQL password and the system root user password are totally different things. The MySQL root password is only for accessing MySQL. Control PanelClick on Servers in the toolbar at the top, then MySQL Database Server, then Change Administration Password Here you can change the MySQL admin (root) password.
Click on Change Now to set the new password. Command LineTo set the MySQL root password from the command line of the Virtual Machine, you will need to connect to the command line of your VM. See the User Guide - Connecting to your Virtual Machine (SSH and Console) http://support.eapps.com/portal/ssh for more information if necessary. Your password will need to pass the cracklib verification, meaning that it must have a minimum of six (6) characters, and at least one special character such as @#$%. This feature is mandatory, and will not be disabled. It does not matter what user you connect with via the command line, since all MySQL commands will be run as the MySQL root user. Remember that all commands within MySQL have to end with a semi-colon ( ; ) or a slash g ( \g ) . First, login to MySQL as the root MySQL user. Remember that at this point, there is no MySQL root password.
Creating databases and database usersOnce MySQL is installed, you can add databases and database users. This can be done from the Control Panel, the command line, or from phpMyAdmin. Creating a database from the Control PanelLogin to the Control Panel, and click on Servers in the toolbar at the top. See the User Guide - Using the Control Panel http://support.eapps.com/control_panel_eapps/control_panel for more information about configuring and accessing the Control Panel. Click on MySQL Database Server, log in with the “root” user name and password (or whatever user you wish) and click on Create a new database. Enter the Database Name – note that it must start with a letter and use only letters, numbers and underscores. Configure anything else you wish to at this point. Click Create. Add a database user from the Control PanelLogin to the Control Panel, and click on Servers in the toolbar at the top. Click on MySQL Database Server, log in with the “root” user name and password (or whatever user you wish) In Global Options click on User Permissions Click on a User name to change the permissions, or click on Create new user to create a new MySQL user. MySQL user details
Click Create to create the user. Creating a database and user from the Command lineTo add a MySQL database and user from the command line, you will first need to connect to the command line of the Virtual Machine. It does not matter what user you connect with via the command line, since all MySQL commands are run as the MySQL root user. Remember that all commands within MySQL have to end with a semi-colon ( ; ) or a slash g ( \g ) . First, login to MySQL as the root MySQL user:
Create the new database:
Create a user that can access this database, along with a password for that user. This password must be a minimum of six (6) characters, and contain at least one special character such as !@#$%.
Test that user and password to make sure they work:
If you go back to the MySQL Databases section in the Control Panel, the new database will show in the Control Panel and the user will appear in User Permissions. You can manage the database and database user from the Control Panel if you wish. Also be aware that only the root MySQL user can see all the databases in MySQL. If you login as another user, you will only be able to see the databases associated with that specific user. Creating a database and user using phpMyAdminphpMyAdmin is a browser based application that will allow you to manage your MySQL databases. To use phpMyAdmin, both it and PHP must be installed. Adding a database and user to phpMyAdminOnce phpMyAdmin is installed, you will will be able to access it via any website or IP address assigned to the Virtual Machine at /myadmin – for example, http://eapps-example.com/myadmin To add a database and database user with phpMyAdmin, you will first need to login to phpMyAdmin as the root MySQL user, with the root MySQL password. Once logged in, you are on the Home screen. Under the MySQL localhost heading, there is a Create new database section. Enter the name of the database, and click Create. (the defaults of Collation and utf8_general_ci can be left as is). Once you click Create, you will be taken to the Structure tab for the new database where you can create a new table. Click on the Privileges tab instead, so you can add a new user for this database. Login Information On the Privileges tab, click Add a new User
Database for user Leave the default of Grant all privileges on database “database_name” checked Global priviliges (Check All/Uncheck All) - Leave this section at the defaults, which should be where everything is unchecked. Click Go to create the user. The next screen shows the new user being created. You can edit their privileges here if needed. Once the database and database user has been created, log out of phpMyAdmin (click the Exit button), and then log back in with the new database user and password to test. The database and database user are also now available in the Control Panel, and can be managed from there. A few notes regarding phpMyAdmin – while phpMyAdmin can be used to manage every part of a MySQL database, do not use it to access sensitive data, because all the information sent to phpMyAdmin is sent in plain text. If you need to access sensitive data using phpMyAdmin, either purchase a commercial SSL certificate or set up a self-signed SSL certificate. See the SSL User Guide for more details. Also be aware that only the root MySQL user can see all the databases in phpMyAdmin. If you login as another user, you will only be able to see the databases associated with that specific user. Importing content to a MySQL databaseThere are several methods available to upload or import data into a MySQL database. Data can be imported from the command line or uploaded through phpMyAdmin. NOTE - All of these examples assume that you have a valid MySQL dump file in .sql format to upload or import Command LineThis example assumes you are familiar with working from the Linux command line, and can easily navigate the file system using standard Linux commands. There is no file size restriction on a MySQL dump file that is being imported from the command line (other than the disk size limitations of your Virtual Machine). See the User Guide - Connecting to your Virtual Machine (SSH and Console) http://support.eapps.com/portal/ssh for more information on how to connect to your VM. The user you connect with to the Virtual Machine is not important, what is important is that you import the database as the correct database user. In this example, a MySQL dump file in sql format called example.sql is being imported to the example_database, which is owned by the
To verify that the content was imported, you can connect to MySQL as the database user, and view the tables.
This should match what you know to be in the SQL file you imported. Another way to view the database content is from the Control Panel, Servers menu item, MySQL Database Server, MySQL Databases. Click on the database in question, this will show the database tables phpMyAdminTo import a MySQL dump file in sql format from phpMyAdmin, login to phpMyAdmin with the database username and password of the user who owns the database. Click on the database name, and once that screen loads, click on the Import tab. With phpMyAdmin, the MySQL dump file has to be located on your local computer. Also, the size of the file that can be uploaded depends on the value of
If the import is successful, there will be a message at the top of the screen that says: Import has successfully finished, some_number of queries executed. Click back on the Home icon in phpMyAdmin, and then select the database. This will now show the database tables. Stopping and starting MySQLMySQL can be stopped/started/restarted from either the Control Panel, or from the command line of the Virtual Machine. Control PanelTo stop, start or restart MySQL from the Control Panel, log in to the Control Panel, and click on the System menu item. MySQL can be restarted from either the MySQL Database Server, or from Service Management. MySQL Database ServerTo stop and start MySQL from the MySQL Database Server module, click the Service ManagementTo stop, start and restart MySQL from Service Management click on the Service Management icon Find and click on the mysqld service Edit Action This screen show the script that is run when the MySQL service starts. You can also configure whether MySQL starts at system boot, and you can Start Now, Restart Now and Stop Now. NOTE - only change values in the Action Script section if you are a MySQL expert, and you know exactly what you are changing and why. Otherwise make no changes here. Command lineTo stop, start or restart MySQL from the command line, you will need to connect to the command line of the VM. Then, as the root user, use one of the following commands: Check the status of MySQL
Stopping MySQL
Starting MySQL
Restarting MySQL
MySQL ConfigurationUsing a my.cnf fileMySQL uses option or configuration files to read startup options from. On your eApps Virtual Machine, this file is my.cnf, located in the /etc directory. If you are creating an /etc/my.cnf file manually, the permissions on the file need to be 644, or A my.cnf file is not necessary to successfully use MySQL. A my.cnf file is only used when some parameter of MySQL has to be changed or specified on startup. If you are creating or modifying a my.cnf file, make sure to read all the appropriate MySQL documentation regarding the settings for that file for your version of MySQL. An incorrectly formatted my.cnf file can cause MySQL to fail on start up, and debugging the my.cnf file is outside of the standard eApps support. The MySQL distribution provides some my.cnf files as examples. These files are located in the /usr/share/mysql directory. The files are my-huge.cnf, my-large.cnf, my-medium.cnf and my-small.cnf. Each file has a description at the top of the file describing the type of system it was designed for. Please read these descriptions carefully and choose the my.cnf file that is appropriate for your needs. To use one of these files, copy it to your /etc directory, and rename it my.cnf. Edit the file to suit your specific needs, and restart MySQL. Make sure that you do not overwrite an existing my.cnf file, especially if you are using MySQL 5.0.4 and above. Sample my.cnf configurationsBelow are some common configurations seen in my.cnf files. Be aware that these configurations are used to solve very specific problems or issues, and are not generally required to successfully use MySQL. Also, understand that using a value in a my.cnf file incorrectly, or with the incorrect syntax, can cause MySQL to fail on start up. Debugging your my.cnf file is outside of the standard eApps support. Use these sample configurations at your own risk! Add these configurations to the my.cnf file either from the File Manager in the Control Panel, or via the command line. After adding the configurations, you will need to restart MySQL. If for some reason MySQL fails to start, remove the changes you made to the my.cnf file, and restart MySQL again.
MySQL remote access setupIf you need to allow access to MySQL from a remote connection, you will need to create a user that can connect remotely. NOTE - To MySQL, the users To create a user with administrative privileges that can connect from a remote workstation, connect to the command line of the VM, and then connect to MySQL as the root user. This example creates a user that can only connect from the eapps-example.com domain
This example creates a user that can connect from any workstation
Now you can use a tool like MySQL Query Browser or Toad to connect to your MySQL database. For assistance with a third party product such as MySQL Query Browser or Toad, please contact the support community for those products. eApps offers no support or assistance for any third party connection tools. JDBC connectionsTo make JDBC connections from your Java application to MySQL, you will need to install a connector on your Virtual Machine to allow MySQL to access the JVM. The connector is called MySQL Connector J (eApps). To install the MySQL Connector J, you will need to log in to the Control Panel and install the application from the Application Manager. Once the MySQL Connector J application is installed, you can create your JDBC connections for your application. Please consult the documentation for your application framework if you need assistance in creating the JDBC connections. Backing up your MySQL databasesBy default, there are no backups taken of your Virtual Machine. Please read the User Guide - Managing Virtual Machine Backups http://support.eapps.com/portal/backups for more information. If you want to make backups of your VM that you can store on the storage array, you will need to purchase additional backup space. WARNING - You need to take responsibility for backing up your mission critical data. If the data is important to you or your business, making sure you have current backups needs to be one of your top priorities. Do not rely on eApps to have your data! There are several strategies you can take to backup your databases. You can use the mysqldump command from the Virtual Machine command line, or the Export feature in phpMyAdmin. Database replication using a master/slave setup is also available – contact the Sales Department for more information on that feature. Using mysqldump to backup your databasesTo backup your databases using mysqldump, you will need to connect to the command line of the VM. The mysqldump commands will need to be run as the system root user, not as the mysql root user. Using mysqldump to back up a single databaseThe mysqldump command can be used to back up a single database. This example shows the
The syntax of the command is: You can enter the password at the -p prompt in the command string if you wish. This is what you would do if you were scripting the backup, for example. Using mysqldump to backup all databasesThe mysqldump command can also be used to make a backup of all databases at once. This is useful if you are going to have to move or backup a large number of databases
This backs up all databases on the Virtual Machine. mysqldump is a complex application, with many options and variables. If you have questions on other uses for mysqldump that are not covered in this User Guide, please reference the official documentation – http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html Using phpMyAdmin to backup your databasesThe phpMyAdmin program has an Export feature that can be used to backup your databases. You can backup either single databases, or select multiple databases, or all databases. To begin, login to phpMyAdmin as the root MySQL user. Click on the Export tab. This will list all the MySQL databases on the Virtual Machine. You can either Select All (or Unselect All), or select multiple databases by holding down the Control key on Windows or the Command key on Mac OS X. After the database or databases are selected, the only thing that has to be checked is the Save as file selection at the bottom of the screen. If you wish to use Compression, select that here also. Then click on Go to download the database to your personal computer. The file will be downloaded as localhost.sql (with a compression type extension if used). It is advisable to change the name of the file to reflect the name of the database (keep the extension unchanged). There are many available options to use for Exporting your databases using phpMyAdmin. The default options should work in most cases. If you have questions on some of the other options, please consult the official phpMyAdmin documentation, which is available by clicking the Question Mark (?) icon in the left navigation pane of the application. The official MySQL documentation is also available by clicking on the SQL icon. Links to other informationMySQL main site - http://www.mysql.com/ MySQL documentation - http://dev.mysql.com/doc/ | |
|