程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> CentOS 6.5上MySQL安裝部署與入門。,centosmysql

CentOS 6.5上MySQL安裝部署與入門。,centosmysql

編輯:MySQL綜合教程

CentOS 6.5上MySQL安裝部署與入門。,centosmysql


centos 6.5 yum 安裝mysql
1、 安裝軟件:yum install -y mysql-server mysql mysql-devel
2、啟動服務:service mysqld start

提示信息:

[root@localhost init.d]# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[ OK ]
Starting mysqld: [ OK ]

  

3、控制台登錄mysql
mysql -u root -p
輸入密碼登錄
mysql>
查看mysql存儲引擎:

mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

  


查詢mysql的數據庫:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)

  


使用某個數據庫:
mysql> use test;
Database changed
查詢某個庫中所有的表:
show tables;

mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.01 sec)

  

查看某個表的結構:

mysql> describe db;
+-----------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| Db | char(64) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
+-----------------------+---------------+------+-----+---------+-------+
22 rows in set (0.00 sec)

  


添加用戶:
授權用戶:

查看某個表的狀態:
mysql> show table status like 'host'
-> ;
+------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------+----------+----------------+---------------------------------------------------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------+----------+----------------+---------------------------------------------------+
| host | MyISAM | 10 | Fixed | 0 | 0 | 0 | 110056715893866495 | 2048 | 0 | NULL | 2015-01-06 21:16:23 | 2015-01-06 21:16:23 | NULL | utf8_bin | NULL | | Host privileges; Merged with database privileges |
+------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------+----------+----------------+---------------------------------------------------+
1 row in set (0.02 sec)

mysql> show table status like 'host'\G
*************************** 1. row ***************************
Name: host
Engine: MyISAM
Version: 10
Row_format: Fixed
Rows: 0
Avg_row_length: 0
Data_length: 0
Max_data_length: 110056715893866495
Index_length: 2048
Data_free: 0
Auto_increment: NULL
Create_time: 2015-01-06 21:16:23
Update_time: 2015-01-06 21:16:23
Check_time: NULL
Collation: utf8_bin
Checksum: NULL
Create_options:
Comment: Host privileges; Merged with database privileges
1 row in set (0.00 sec)
創建表:
create table user_test(id int,sex char(2));#默認使用MyISAM存儲引擎。也可以指定存儲引擎。
如:
create table user_test(id int,sex char(2))engine=InnoDB;

修改表的存儲引擎:
alter table user_test engine=csv;
mysql> alter table user_test engine=csv;
ERROR 1178 (42000): The storage engine for the table doesn't support nullable columns

由錯誤可得:csv引擎存儲的表,列不得為空。

alter table user_test engine=MEMORY;
mysql> alter table user_test engine=MEMORY;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
memory存儲的表常用作臨時表使用。它使用散列索引,所以數據的存取速度非常快。因為是存在於內存中,所以這種類型常應用於臨時表中。

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved