查看mysql安装情况
[root@localhost ~]# rpm -e mysql
error: package mysql is not installed
直接yum安装
[root@localhost ~]# yum install -y mysql-server mysql mysql-devel
Loaded plugins: fastestmirror, refresh-packagekit, security
Repository c6-media is listed more than once in the configuration
Determining fastest mirrors
* base: mirrors.pubyun.com
* extras: mirrors.pubyun.com
* updates: mirrors.pubyun.com
查看安装情况
[root@localhost mysql]# rpm -qa | grep sql
默认头文件和库文件目录分别如下:
[root@localhost mysql]# rpm -ql mysql-devel.i686 0:5.1.73-3.el6_5
/usr/include/mysql
/usr/include/mysql/decimal.h
/usr/include/mysql/errmsg.h
/usr/include/mysql/keycache.h
/usr/include/mysql/m_ctype.h
/usr/lib/mysql
/usr/lib/mysql/libmysqlclient.so.16
/usr/lib/mysql/libmysqlclient.so.16.0.0
/usr/lib/mysql/libmysqlclient_r.so.16
/usr/lib/mysql/libmysqlclient_r.so.16.0.0
查看版本信息
[root@localhost ~]# rpm -qi mysql-server
Name : mysql-server Relocations: (not relocatable)
Version : 5.1.73 Vendor: CentOS
Release : 3.el6_5 Build Date: Wed 12 Feb 2014 11:09:08 AM PST
Install Date: Wed 03 Sep 2014 10:17:38 AM PDT Build Host: c6b9.bsys.dev.centos.org
启动mysql
[root@localhost ~]# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
查看并配置自启动
[root@localhost ~]# chkconfig --list|grep mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off6:off
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig --list|grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
设置密码并登陆
[root@localhost ~]# mysqladmin -u root password 'beyond'
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
检查正常
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
mysql主要配置信息
[root@localhost code]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)
[root@localhost ~]# mysql -h localhost -u root -p123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
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>
[root@localhost ~]# mysql -h 192.168.109.128 -P 3306 -u root -p123
[root@localhost ~]# mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
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>
MySQL 连接本地数据库,用户名为“root”,指定所连接的数据库为“test”
[root@localhost ~]# mysql -h localhost -u root -p123 -D test
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
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>