centos6.5下安装mysql
时间:2014-08-12 01:11来源:blog.csdn.net 作者:brushli 举报 点击:17509次
1.使用yum命令安装mysql
[html] view plaincopy
[root@bogon ~]# yum -y install mysql-server
2.设置开机启动
[html] view plaincopy
[root@bogon ~]# chkconfig mysqld on
3.启动MySQL服务
[html] view plaincopy
[root@bogon ~]# service mysqld start
4.设茄滑置MySQL的root用户设置密码
[html] view plaincopy
[root@bogon ~]# mysql -u root
mysql>select user,host,password from mysql.user
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
+------+-----------+----------+
5 rows in set (0.01 sec)
查询用户的密码,都为空,用下面的命令设置root的密码为root
[html] view plaincopy
mysql>set password for root@localhost=password('root')
mysql>exit
5.用新密码登陆
[html] view plaincopy
[root@bogon ~]# mysql -u root -p
Enter password:
6.创建mysql新用户test_user
[html] view plaincopy
mysql>create user 'test_user'@'%' identified by 'test_user'
Query OK, 0 rows affected (0.00 sec)
7.给新用户test_user授权,让他可以从外部登陆和本地弯山登陆
注意:@左边是用户名,右边是域名、IP和%,表示可以访问mysql的域名和IP,%表埋纳中示外部任何地址都能访问。
[html] view plaincopy
mysql>grant all privileges on *.* to 'test_user'@'localhost' identified by 'test_user'
Query OK, 0 rows affected (0.00 sec)
mysql>grant all privileges on *.* to 'test_user'@'%' identified by 'test_user'
Query OK, 0 rows affected (0.00 sec)
mysql>select user,host,password from mysql.user
+----------+-----------+-------------------------------------------+
| user | host | password |
+----------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
| test_user | % | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
| test_user | localhost | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
+----------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)
mysql>flush privileges
Query OK, 0 rows affected (0.01 sec)
8.查看mysql5.1的默认存储引擎
从下面的执行结果可以看出,mysql的默认引擎是MyISAM,这个引擎是不支持事务的。
[html] view plaincopy
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)
也可以以下面的方式查看
[html] view plaincopy
mysql>show variables like 'storage_engine'
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | MyISAM |
+----------------+--------+
1 row in set (0.00 sec)
9.修改mysql的默认引擎为InnoDB
9.1 停止mysql
[html] view plaincopy
mysql>exit
[root@bogon ~]# service mysqld stop
9.2 修改/etc/my.cnf
[mysqld] 后加入
[html] view plaincopy
default-storage-engine=InnoDB
加入后my.cnf的内容为:
[html] view plaincopy
[root@bogon etc]# more 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
default-storage-engine=InnoDB
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
9.3 启动mysql
[html] view plaincopy
[root@bogon etc]# service mysqld start
Starting mysqld: [ OK ]
9.4 查看mysql默认存储引擎
[html] view plaincopy
[root@bogon etc]# mysql -u root -p
Enter password:
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>show variables like 'storage_engine'
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.00 sec)
10.CentOS6.5开放mysql端口3306
CentOS6.5默认是不开放端口的,如果要让外部的系统访问CentOS6.5上的mysql,必须开放mysql的端口3306
10.1 修改/etc/sysconfig/iptables
添加下面一行
[html] view plaincopy
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
修改后iptables中的内容是
[html] view plaincopy
[root@bogon etc]# more /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#添加配置项
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
11.重启防火墙
[html] view plaincopy
[root@bogon etc]# service iptables restart
这样就可以从外部访问mysql了。
至此,mysql在CentOS6.5上的安装过程、用户创建、外部访问的步骤全部完成。
查看文件安装路径在终端输入:whereismysql回车,如果你安装好了mysql,就会显示文件安装的地址,例如我的显示(安装地址桐脊祥可能会不同)[root@localhost~]#whereismysqlmysql:/usr/bin/mysql/usr/lib/mysql/usr/share/mysql/局搏usr/share/man/man1/mysql.1.gz说明:usr/野粗lib/mysql是指:mysql的安装路径免编译版本的MySQL很方便,省了好多时间,我用的是mysql5.5-x86_64版本,接下来是在CentOS6.5安装过程,就那么几个步骤。#安装依赖包
yum install -y libaio-devel
#创建用户
useradd -s /sbin/nologin mysql
#创建数据目录
mkdir -p /data/mysql
#赋予权限
chown -R mysql:mysql /data/mysql
#解压
tar zxvf mysql-5.5.42-linux2.6-x86_64.tar.gz
#移动到指定目录
mv mysql-5.5.42-linux2.6-x86_64 /usr/local/mysql
#因为系统有一个默认my.cnf,咱们给它改下名字
mv /etc/my.cnf /etc/my.cnf.default
#复制我们需要的my.cnf到指定目录升伍
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
#在support-files目录下有几个cnf,根据内存大小来选择
my-small.cnf (内存<=64M)
my-medium.cnf (内存128M)
my-large.cnf (内存512M)
my-huge.cnf (内存1G-2G)
my-innodb-heavy-4G.cnf (内存4GB)
#编辑我们复制过去的my.cnf,并且在[mysqld]的下一行那里插入以下内容
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
character-set-server=utf8
#添加环境变量,在末尾插入以下内容
vi /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
#让刚才的修改生效
source /etc/profile
#复制启动脚本到指定目录
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#准备工作都做完了,开始初始化数据库
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
#启动数据库
service mysqld start
#开机启动
chkconfig mysqld on
#初始化迟笑举mysql的一些设置
mysql_secure_installation
#回车
Enter current password for root (enter for none):
#y,设置mysql的root密码
Set root password?[Y/n] y
#以下都yes
Remove anonymous users?[Y/码碧n] y
Disallow root login remotely?[Y/n] y
Remove test database and access to it?[Y/n] y
Reload privilege tables now?[Y/n] y
ThanksforusingMySQL!
OK,完成。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)