Presentation is loading. Please wait.

Presentation is loading. Please wait.

MySQL Getting Started BCIS 3680 Enterprise Programming.

Similar presentations


Presentation on theme: "MySQL Getting Started BCIS 3680 Enterprise Programming."— Presentation transcript:

1 MySQL Getting Started BCIS 3680 Enterprise Programming

2 Quick Verification  Run mysqlshow –u root –p  Enter the password when prompted.  If you can see a listing of the databases that come with MySQL, your installation is good. 2

3 Another Fast Check  List the tables in the included “mysql” DB by running: mysqlshow mysql –u root –p 3

4 Now You’re Ready to Go! 4  To get out of MySQL, type “exit” at the MySQL prompt and then press Enter.

5 Making Your Data Files Portable  If you want share the same database files between VM and home computers (or between multiple computers you own), you need to do the following:  Copy the default data folders to your USB drive.  Change MySQL’s database directory (the datadir setting) to the one on your USB drive.  MySQL runs just fine from its default datadir. However, whether you are using the default or not, you should be able to locate and change your database folder. 5

6 Making Your Data Files Portable  Browse to the default database folder of MySQL.  Right-click the data subfolder and select “Copy” (do not open the folder).  You may need to change your Windows Explorer setting to show hidden files and folders. 6 Right-click and select “Copy” We will come back and edit this file later.

7 Default DB Folder 7  Windows 8 & Windows 7 C:\ProgramData\MySQL\MySQL Server 5.6\data  C:\programData is a hidden folder. Change the Windows Explorer setting to show hidden folders and files.  Windows Vista C:\Users\All Users\MySQL\MySQL Server 5.6\data  Windows XP C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6\data  C:\Documents and Settings\All Users\Application Data is a hidden folder. Change the Windows Explorer setting to show hidden folders and files.

8 Duplicating DB Folder  On your USB drive, create a folder called BCIS3680 (if you are currently using a folder of this name for you JSPs, then use a different folder, such as BCIS3680DB ).  Open BCIS3680.  Right-click and select “Paste”.  Now you have copied the data directory from the default location to your USB drive. 8

9 Start Console with Admin Rights 9 As with Tomcat, start a command console with administrator rights if you use Windows Vista or higher

10 Start Console with Admin Rights 10

11 Changing MySQL Default Data Folder  Run net stop mysql  Wait until you see the message saying that the service was stopped successfully. 11

12 Editing my.ini  At the same level of the \data subfolder, find the file by the name my.ini.  Start Notepad with admin rights or Notepad++ to edit it. 12 Do not double-click. Instead, open Notepad with administrator rights. Then, inside Notepad, click File | Open. Browse to and open this file.

13 Start NotePad with Admin Rights 13 Again, open Notepad with administrator rights if you use Windows Vista or higher

14 Start NotePad with Admin Rights 14

15 Editing my.ini  Open the my.ini file and scroll down to find the [mysqld] section.  Find the line starting with datadir="C:/Documents…  Add a # sign at the very beginning of that line to “comment it out”.  Below that line, add a new line that says: datadir="E:/BCIS3680/data/"  This should be the path to the folder you used in Slide #5, so make changes if your folder is different from the above example.  Use forward slashes instead of backward slashes.  Don’t modify anything else in that file! If you think you have done so by mistake, close it without saving and start over again. 15

16 Edited my.ini  Once you’re done, save the file and close the window. 16

17 Restarting MySQL Server  Run net start mysql  Wait until you see the message saying that the service was started successfully. 17

18 Verifying Change of datadir  Run mysql –u root –p  If you work on a lab computer, when prompted, enter bcis3680 (or whatever password you set) as your password.  You should be able to log in as the root user. 18

19 Verifying Change of datadir  Run show variables like 'datadir';  If you see E:\BCIS3680\data\ in the value column (note that in the example it’s C:\data\ ), then you have successfully changed the database directory for the current session to the folder on your USB drive. 19

20 Log in to MySQL  Run mysql –u root –p to log in  -u option for username  -p will enter password  Run use ; to select the database you want to work with.  To log out, type either  \q  exit  Quit or  press Ctrl + C 20

21 MySQL Commands  A MySQL command ends with a semicolon, except: quit, exit  In comparison, the net stop, net start, and mysql commands are Windows commands and appending semicolon to them would generate an error.  You may split a complex, long command over multiple lines. It will not run until you hit the ; key and then Enter.  For even more complex input of commands, you may group the commands into a script file. Then run source ; to execute the script. 21

22 The Forta Database  Download the forta scripts from the course site.  Use these scripts from my website instead of those from the author/publisher.  I modified the scripts so that the database so created can be accessed from both the lab and your home computers without problems.  Create a database called forta in MySQL.  Unzip and run the two scripts ( create.sql and populate.sql ) to create and populate tables in that database. 22

23 Create the Forta Database 23  Run create database forta; to create the forta DB.  Run show databases; to verify.

24 Run Script to Create Tables 24  Run use forta; to actually work on that DB.  Run source to create tables.

25 Run Populate Script to Add Data 25  Run source to populate the tables.  Now you will be able to follow along while reading the Forta book.

26 Display Names of Tables in DB 26  Run show tables; to show tables in the forta DB.


Download ppt "MySQL Getting Started BCIS 3680 Enterprise Programming."

Similar presentations


Ads by Google