Centos安装mysql一般步骤

查看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> 


MySQL 连接远程数据库(192.168.109.128),端口“3306”,用户名为“root”,密码“123”

[root@localhost ~]# mysql -h 192.168.109.128 -P 3306 -u root -p123


MySQL 连接本地数据库,用户名为“root”,隐藏密码

[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> 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值