In this second part of a four-part series on Perl and the DBI, you'll learn how to create a database and how to use a collection of very important commands. This article is excerpted from chapter 15 of the book Beginning Perl by James Lee (Apress; ISBN: 159059391X).
It is important to create a non-root user to access the database—performing normal non-MySQL-admin activities using the root user is a bad idea for security reasons. So let’s create a user that will be allowed to perform basic queries on themusicians_dbdatabase:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE -> ON musicians_db.* -> TO musicfan@localhost -> IDENTIFIED BY "CrimsonKing"; Query OK, 0 rows affected (0.03 sec)
You can trust us when we say that this command creates a user namedmusicfan with a password “CrimsonKing”5 and grants this user permission to select, insert, update, and delete records from the database. Or, you can check out the documentation and read all about theGRANTcommand.
We are going to start inserting data into ourmusicians_dbdatabase, so we need to log out as therootuser and log back into MySQL as the newly createdmusicfanuser:
mysql> quit Bye $ mysql -u musicfan -p Enter password: CrimsonKing