Install and use MySQL in Ubuntu

Source: Internet
Author: User

MySQL installation and use notes in Ubuntu $ sudo apt-get install mysql-server mysql-client mysql server start, close, and restart $ sudo/etc/init. d/mysql start/stop/restart set the initial password $ mysqladmin-u root-p password change your password $ mysqladmin-u root-p password your new password (begin will prompt you to enter original password) enter password: mysql Log on to the local server (for example, log on to the root user) $ mysql-uroot-p or: Enter password: $ mysql-hlocalhost-uroot-p mysql Log on to the remote server (for example, log on to the root user) $ mysql-h hostname/ip-P portnum-ur Oot-p Enter password: Note-P (uppercase) specifies the port number. This parameter can be omitted. If this parameter is omitted, the default port 3306 is connected. create a new user and Set permissions (GRANT command) GRANT can be used to create a user and Set permissions at the same time. You can also set or modify permissions for an existing user in a similar way. The format of GRANT is as follows: grant <privileges> on database object (database. table) to user (user @ host) [identified by "<password>"] [with grant option]; (1) if identified by "<password> ", if user @ host does not exist, this command creates a new user and specifies the permission <privileges>. If user @ host exists, this command specifies the permission <privileges>, if the password is different from the original password, it is changed to a new password. Therefore, if identified by is specified, GRANT can create users, modify passwords, and specify permissions. (2) If identified by is not specified, GRANT can be used to specify permissions, that is, you do not need to specify a password to set or modify permissions. (3) The <privileges> field can be specified as "all privileges" to indicate ALL permissions, or other specified permission fields separated by commas (,); (4) database. the table field indicates a table in a database ,*. * Indicates all tables of all databases, dbname. * Indicates all tables of the database dbname. (5) The user @ host field indicates the user on the host, and the user @ localhost indicates that the user can only be accessed locally, user @ "%" indicates that the user can be accessed from any host, user @ '192. 168.0.1 'indicates that the user can only access from the specified host. Example: For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type: $ mysql> grant all privileges on *. * TO 'yourusername' @ 'localhost' identified by 'yourpassword' with grant option; For creating a new user with fewer privileges (shocould work for most web applications) which can only use the database named "database1", at mysql prompt type: $ mysql> grant select, INSER T, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, create temporary tables, lock tables on database1. * TO 'yourusername' @ 'localhost' identified by 'yourpassword '; yourusername and yourpassword can be anything you like. database1 is the name of the database the user gets access. localhost is the location which gets access to your database. you can change it to '%' (or to hostnames or ip addresses) Allow connections from every location (or only from specific locations) to the database. Note, that this can be a security problem and shocould only be used for testing purposes! [Detailed usage of GRANT can be viewed from the Internet] view user Permissions $ mysql> show grants for user @ host; $ mysql> show grants for user; equivalent: $ mysql> show grants for user @ "% ";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.