You can send SQL to MySQL using a variety of mechanisms. The most common way is through one of the programming APIs described in Part III. For the purposes of this chapter, however, we recommend you use the interactive command-line tool, mysql . When you run this program at the command line, it prompts you for SQL:
[09:04pm] carthage$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.22.29 Type 'help' for help. mysql>
The previous mysql command says to connect to the MySQL server on the local machine as the user root (the -u option) with the client prompting you for a password (the -p option). Another option, -h, enables you to connect to MySQL servers on remote machines:
[09:04pm] carthage$ mysql -u root -h db.imaginary.com -p
There is absolutely no relationship between operating-system usernames and MySQL usernames. In other words, MySQL keeps its own list of users, and a MySQL administrator needs to add new users to MySQL independently of the host on which they reside. No one, therefore, has an account on a clean MySQL installation except root. This root is not the same root as your Unix root account. As a general rule, you should never connect to MySQL as root except when performing database administration tasks. If you have a clean installation of MySQL that you can afford to throw away, it is useful to connect as root for the purposes of this chapter so you can create ...