mysql相关知识点整理
一、安装
1、查看系统中是否已安装mysql
[root@master ~]# yum list installed mysql* 已加载插件:fastestmirror, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Determining fastest mirrors base | 3.7 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 1.5 MB 00:00 已安装的软件包 mysql-libs.x86_64 5.1.71-1.el6 @anaconda-RedHatEnterpriseLinux-201311111358.x86_64/6.5 [root@master ~]# yum list mysql* 已加载插件:fastestmirror, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Loading mirror speeds from cached hostfile 已安装的软件包 mysql-libs.x86_64 5.1.71-1.el6 @anaconda-RedHatEnterpriseLinux-201311111358.x86_64/6.5 可安装的软件包 MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 base mysql.x86_64 5.1.73-3.el6_5 base mysql-bench.x86_64 5.1.73-3.el6_5 base mysql-connector-java.noarch 1:5.1.17-6.el6 base mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base mysql-devel.i686 5.1.73-3.el6_5 base mysql-devel.x86_64 5.1.73-3.el6_5 base mysql-embedded.i686 5.1.73-3.el6_5 base mysql-embedded.x86_64 5.1.73-3.el6_5 base mysql-embedded-devel.i686 5.1.73-3.el6_5 base mysql-embedded-devel.x86_64 5.1.73-3.el6_5 base mysql-libs.i686 5.1.73-3.el6_5 base mysql-libs.x86_64 5.1.73-3.el6_5 base mysql-server.x86_64 5.1.73-3.el6_5 base mysql-test.x86_64 5.1.73-3.el6_5 base
2、查看现有安装包
[root@master ~]# yum list mysql* 已加载插件:fastestmirror, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Loading mirror speeds from cached hostfile 已安装的软件包 mysql.x86_64 5.1.73-3.el6_5 @base mysql-devel.x86_64 5.1.73-3.el6_5 @base mysql-libs.x86_64 5.1.73-3.el6_5 @base mysql-server.x86_64 5.1.73-3.el6_5 @base 可安装的软件包 MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 base mysql-bench.x86_64 5.1.73-3.el6_5 base mysql-connector-java.noarch 1:5.1.17-6.el6 base mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base mysql-devel.i686 5.1.73-3.el6_5 base mysql-embedded.i686 5.1.73-3.el6_5 base mysql-embedded.x86_64 5.1.73-3.el6_5 base mysql-embedded-devel.i686 5.1.73-3.el6_5 base mysql-embedded-devel.x86_64 5.1.73-3.el6_5 base mysql-libs.i686 5.1.73-3.el6_5 base mysql-test.x86_64 5.1.73-3.el6_5 base [root@master ~]#
3、安装mysql服务器段
[root@master ~]# yum install mysql-devel.x86_64 [root@master ~]# yum install mysql-server.x86_64
4、安装mysql客户端(可选)
[root@master ~]# yum install mysql
二、配置
1、设置默认字符和引擎
[root@master ~]# vim /etc/my.cnf
在[mysqld]下添加
default-character-set=utf8 default-storage-engine=INNODB
三、启动和关闭
1、启动和关闭
[root@master ~]# /etc/init.d/mysqld start
[root@master ~]# /etc/init.d/mysqld stop 停止 mysqld: [确定]
2、开机启动
[root@master ~]# chkconfig --list | grep mysql mysqld 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 [root@master ~]#
[root@master ~]# chkconfig add mysqld chkconfig 版本 1.3.49.3 - 版权 (C) 1997-2000 Red Hat, Inc. 在 GNU 公共许可的条款下,本软件可以被自由发行。 用法: chkconfig [--list] [--type <type>] [name] chkconfig --add <name> chkconfig --del <name> chkconfig --override <name> chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities> [root@master ~]# chkconfig --add mysqld
[root@master ~]# chkconfig mysqld on
[root@master ~]# chkconfig --list | grep mysql mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 [root@master ~]#
更多安装配置相关详情,参看原博文:redhat下mysql安装与使用
四、启动mysql
[root@master ~]# mysql ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
问题原因:未启动mysql
1、启动mysql
[root@master ~]# /etc/rc.d/init.d/mysqld start 正在启动 mysqld: [确定]
[root@master ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> status -------------- mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 Connection id: 2 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: ‘‘ Using delimiter: ; Server version: 5.1.73 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 10 sec Threads: 1 Questions: 5 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 0.500 --------------
五、mysql的使用
1、查看mysql帮助信息
mysql> \h For information about MySQL products and services, visit: http://www.mysql.com/ For developer information, including the MySQL Reference Manual, visit: http://dev.mysql.com/ To buy MySQL Enterprise support, training, or other products, visit: https://shop.mysql.com/ List of all MySQL commands: Note that all text commands must be first on line and end with ‘;‘ ? (\?) Synonym for `help‘. clear (\c) Clear the current input statement. connect (\r) Reconnect to the server. Optional arguments are db and host. delimiter (\d) Set statement delimiter. edit (\e) Edit command with $EDITOR. ego (\G) Send command to mysql server, display result vertically. exit (\q) Exit mysql. Same as quit. go (\g) Send command to mysql server. help (\h) Display this help. nopager (\n) Disable pager, print to stdout. notee (\t) Don‘t write into outfile. pager (\P) Set PAGER [to_pager]. Print the query results via PAGER. print (\p) Print current command. prompt (\R) Change your mysql prompt. quit (\q) Quit mysql. rehash (\#) Rebuild completion hash. source (\.) Execute an SQL script file. Takes a file name as an argument. status (\s) Get status information from the server. system (\!) Execute a system shell command. tee (\T) Set outfile [to_outfile]. Append everything into given outfile. use (\u) Use another database. Takes database name as argument. charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. warnings (\W) Show warnings after every statement. nowarning (\w) Don‘t show warnings after every statement. For server side help, type ‘help contents‘ mysql>
2、退出mysql
mysql> \q Bye [root@master ~]#
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。