Mysql installation and use (this is very good, change your password)

xiaoxiao2021-03-06  40

First, what is mysql mysql (pronounced "My Ess Que ELL") is a multiplayer developed by TCX (http://www.tcx.se), multi-execute SQL Database Server. MySQL's main goal is fast, stable and easy to use. MySQL can be obtained at this http://www.mysql.net/. Second, MySQL installation This article is used by mysql-3.22.27.tar.gz (original code archive), the job environment is RedHat6.0 Cle0.8. The mysql preset is installed in / usr / local directory, but for future removal, it is recommended to install MySQL independently in the / usr / local / mysql directory. Under the step of installing MySQL: obtain mysql-3.22.27.tar.gz, unlocked in / usr / local directory: # cd / usr / local # tar zxvf mysql-3.22.27.tar.gz # cd mysql -3.22.27 Set the Configure installation option, select the installation directory (Prefix) and support the Chinese BIG5 code (with-charset = BIG5): # ./configure --prefix = / usr / local / mysql / # - with-charset = BIG5 starts to compile and install: # make # make install # scripts / mysql_install_db The last step is to generate mysql grant Tables (will create a MySQL database and some tables, which are used to manage authorization information using mysql, that is, users What are the use of the database permission). Third, start, stop mysql to start mysql method: (Install mysql installation in / usr / local / mysql as an example) # /usr/local/mysql/share/mysql.server Start pay attention to the first execution, Mysql.server is required to be executed (ChMOD 744 mysql.server), and you can add this line instruction to the /etc/rc.d/rc.local file, let MySQL start automatically when booting. To stop mysql method: # / usr / local / mysql / bin / mysqladmin shutdown If you have a password for the MySQL Administrator root account (non-job system root), stop mysql must do this, MySQL will ask you After the root's password, Shutdown's work is performed: # / usr / local / mysql / bin / mysqladmin -u root -p Shutdown IV 4. Manage and use MySQL Introduction to Mysql before you start MYSQL to come with MySQL Database Server connection, the most important of which is the mysql conversation tool with mysqladmin utilities, and most of the user will talk with the database Server with MySQL. Under the end, you will use MySQL wiring tools to describe how to maintain and use mysql. (Installed in this article as an example, MySQL tool is located in / usr / local / mysql / bin / mysql).

MySQL's use syntax is as follows: mysql [-u username] [-h host] [-p [password]] [dbname] MySQL database has its own set of user account and permission control method, so the username specified by this Password is MySQL user and password, not the user and password of the job system (of course any user can perform MySQL, then enter using any account in MySQL). When you first install MySQL, MySQL's management account is root, no password (ROOT for non-job system). So before the beginning, please take the following steps to set the password for root: Use mysql and mysql database Server connection: # / usr / local / mysql / bin / mysql -u root mysql ready and column Names you can turn the mysql monTure to get a quicker startup with --a welcome to the mysql monitor. comMMands end with; or / g. Your mysql connection ID is 201 to Server Version: 3.22.27 Type 'Help' for Help. MySQL > In the mysql -u root mysql directive, specify the root account and turn on the MySQL system database, after connecting to mysql, you will see some prompts with the MySQL tool, and most of the work will be prompted here. The symbol is completed. Change MySQL System Manager root password: mysql> Update user set password = password ('new password') Where user = 'root'; query ok, 0 rows affected (0.00 sec) Rows match: 2 Changed: 0 Warnings: 0 mysql > Flush privileges; query ok, 0 rows affected (0.00 sec) mysql> quit bye pay attention to a semicolon ";" will then let MySQL begin. The second instruction will update the Mysql system library that has been loaded into the memory, and finally leave the MySQL tool program. After updating the root password, the way to connect with the MySQL connection in the future is: mysql -u root -p new password or so, let MySQL ask the root password: mysql -u root -p Database Maintenance Next, we are simple As an example, the address book is used to introduce how to use the MySQL tool program to do the maintenance of the database (new, authorization, information sheet maintenance, etc.).

First, establish an addbook database after connecting with the mysql root account: # / usr / local / mysql / bin / mysql -u root -p Enter Password: Welcome to the mysql monitor. Commands end with; or / g. Your mysql Connection ID is 207 TO Server Version: 3.22.27 Type 'Help' for Help. MySQL> CREATE DATABAE Addbook; Query OK, 1 ROW Affected (0.00 sec) Specify Using the Addbook Database and establish a Friends Data Sheet: MySQL> USE Addbook; Database Changed Mysql> Create Table Friends (-> Name Char (15), -> Telphone VARCHAR (20), -> ICQ Char (10), -> Address VARCHAR (30) ->); Query Ok, 0 ROWS Affected (0.00 sec) add a number of information, query look: mysql> Insert Into Friends Values ​​(-> "MAA", "29016710", "46243046", "Taipei County Xinzhuang" ->); query ok, 1 Row Affected (0.00 Sec) Mysql> Insert Into Friends (Name, ICQ, Telphone, Address) Values ​​(-> "CXLIN", "39425893", "7654321", "Taipei County" ->); Query Ok, 1 ROW Affected (0.01 sec) mysql> select * from friends; ------- -------- ---------- ----- ------- | Name | Telphone | ICQ | Address | ------- -------- -------- - --- --------- | MAA | 29016710 | 46243046 | Taipei County Xinzhuang | | CXLIN | 7654321 | 39425893 | Taipei County | ------- ------- - ---------- -------------- 2 ROWS IN Set (0.00 sec) The second INSERT directive specifies the insert order of the data field, The usage is the first one is elastic, and the first instruction must be inserted into the order in order to establish a structure according to the data sheet.

Update, delete data sheet record: mysql> Update friends set address = "Taoyuan County" where name = "cxlin"; Query Ok, 1 row affected: 1 Changed: 1 Warnings: 0 mysql> Select * from Friends where name = "cxlin"; ------- -------- -------- --------- | Name | Telphone | ICQ | Address | ------ ---------- -------- ------- | CXLIN | 7654321 | 39425893 | Taoyuan County | ------- -------- ---------- --------- 1 row in set (0.00 sec) mysql> delete from friends where name = "maa"; query ok, 1 row affed (0.01 sec) mysql> select * from friends; ------ ---- ------ ---------- --------- | Name | Telphone | ICQ | Address | ------ ------ ------ ---------- --------- | CXLIN | 7654321 | 39425893 | Taoyuan County | ------- --- ------- ---------- --------- 1 ROW IN Set (0.00 sec) Finally, after building the database and the information sheet, put the addbook Authorization of all data sheets (SELECT, INSERT, UPDATE, DELETE) authorized to MAA @ localhost (reminder again, the maa account for this MAA is mysql, not the MAA account number of the job system): mysql> GRANT SELECT, INSERT, UPDATE, DELETE -> on addbook. * -> to maa @ localhos T Identified by '1234567'; Query OK, 0 ROWS Affected (0.00 sec), available MAA's identity into MySQL access addbook database: # / usr / local / mysql / bin / mysql -u maa -p Addbook Enter Password : Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor Commands end with; or / g Your MySQL connection id is 211 to server version:. 3.22. .27 Type 'Help' for help. Mysql>

Status -------------- ./mysql Ver 9.36 Distrib 3.22.27, for PC-Linux-GNU (I686) Connection ID: 26 CURRENT DATABASE: ADDBOOK CURRENT USER: MAA @ localhost server version 3.22.27 Protocol Version 10 Connection Localhost Via UNIX Socket Unix Socket /TMP/Mysql.sock Uptime: 2 Hours 29 min 33 Sec Threads: 11 Questions: 107 Slow Queries: 0 Opens: 11 Flush Tables: 1 Open 7 ---- ---------- Remove the use of the library Use the right to use (enter): mysql> Revoke delete on addbook. * From maa @ localhost; query ok, 0 rows affected (0.00 sec) mysql> Revoke all privileges on addbook. * from maa @ localhost; query OK, 0 ROWS AFFECTED (0.00 sec) The second instruction is used to recover all permissions. 5. The use of mysqladmin utilities can be used to maintain Mysql's relatively general work (new, delete database, set user password and stop mysql, etc.), detailed instructions can be viewed using mysqladmin --help . (Installed in this article as an example of mysqladmin located in / usr / local / mysql / bin / mysqladmin).

转载请注明原文地址:https://www.9cbs.com/read-64556.html

New Post(0)