
- #How to add a user account in mysql command line how to
- #How to add a user account in mysql command line password
Replace dbname with the name of the database that you want to create, and tablename with the name of the table that you want to create. INSERT INTO tablename ( id, name ) VALUES ( null, 'Sample data' ) Copy and paste the following text into the file:ĬREATE TABLE tablename ( id smallint unsigned not null auto_increment, name varchar( 20) not null, constraint pk_example primary key (id) )
#How to add a user account in mysql command line password
If you have assigned a password to the root account, you must also supply a -password or -p option. The above command connects you to MySQL server interface with root user. GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY 'password' Ĭreate a file named example.sql and open it in your preferred text edtior. Once you are in Linux / Ubuntu command line enter below command to access MySQL server.
#How to add a user account in mysql command line how to
The following procedure demonstrates how to use a SQL script file to create and populate a database: Learn how to connect to MySQL from the command line using the MySQL program with this guide including detailed instructions, code snippets and links to related articles. However, you can streamline the process by combining commands into a SQL script file. The previous procedure demonstrates how to create and populate a MySQL database by typing each command interactively with the mysql program. INSERT INTO example ( id, name ) VALUES ( null, 'Sample data' ) For example, the following commands demonstrate how to create a basic table named example, and how to insert some data into it:ĬREATE TABLE example ( id smallint unsigned not null auto_increment, name varchar( 20) not null, constraint pk_example primary key (id) ) Replace dbname with the name of the database you created in step 7: To work with the new database, type the following command. The mysql program processes the script file statement by statement. Replace username with the name of the user you created in step 1. To process the SQL script, type the following command. Replace dbname with the name of the database that you want to create: Save the changes to the example.sql file and exit the text editor. To create a database, type the following command. Type the user's password, and then press Enter.Replace username with the name of the user you created in step 3: To log in to MySQL as the user you just created, type the following command. For example, to explicitly grant only the SELECT permission for the specified user, you would use the following command: GRANT SELECT ON *.* TO grant the user all permissions only on the database named dbname, you would use the following command: GRANT ALL PRIVILEGES ON dbname.* TO more information about setting MySQL database permissions, please visit 5.5/en/grant.html. mysql> CREATE USER 'myuser''localhost' IDENTIFIED BY 'mypassword' Once a user is created, all its account details including an encrypted password, privileges and resource limits are stored in a table called user in a special database named mysql. However, you can grant specific permissions to maintain precise control over database access. To create a new user with username myuser and password mypassword, use the following command. The previous command grants the user all permissions on all databases.
