安装前准备(CentOS6.5搭建)
所需要的软件包(安装5.5.22需要cmake)
cp cmake-2.8.6.tar.gz mysql-5.5.22.tar.gz /root
配置yum
cd /etc/yum.repos.d/ && mkdir yum && mv *.repo yum && cp yum/CentOS-Media.repo . && vim CentOS-Media.repo
关闭防火墙 和 selinux
service iptables stop && chkconfig iptables off && setenforce 0
检查是否有rpm安装的mysql
rpm -q mysql-server mysql (如果有建议卸载rpm -e mysql-server mysql --nodeps)
2.开始安装mysql数据库
yum install -y ncurses-devel
解压cmake
tar -zxf cmake-2.8.6.tar.gz && tar -zxf mysql-5.5.22.tar.gz
编译cmake
cd cmake-2.8.6 && ls && ./configure
安装cmake
gmake && gmake install
解压mysql
tar -zxf mysql-5.5.22.tar.gz && cd mysql-5.5.22
编译安装mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install
建立配置文件
[root@CentOS6-node1 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
添加为系统服务
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
[root@CentOS6-node1 mysql-5.5.22]# chkconfig --add mysqld
[root@CentOS6-node1 mysql-5.5.22]# chkconfig --list mysqld
mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
设置环境变量
[root@CentOS6-node1 mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@CentOS6-node1 mysql-5.5.22]# . /etc/profile
建立mysql组 mysql用户
[root@CentOS6-node1 mysql-5.5.22]# groupadd mysql && useradd -M -s /sbin/nologin mysql -g mysql
将/usr/local/mysql/的属组属主改为mysql
[root@CentOS6-node1 mysql-5.5.22]# chown -R mysql:mysql /usr/local/mysql/ && ls -l /usr/local/mysql/
初始化msyql数据库
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
启动mysql服务
[root@CentOS6-node1 mysql-5.5.22]# service mysqld start
Starting MySQL.. [确定]
查看数据库状态
[root@localhost mysql-5.5.22]# /etc/init.d/mysqld status
MySQL running (22493) [确定]
查看数据库的信息
[root@localhost mysql-5.5.22]# netstat -anpt | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22493/mysqld
开机自启
[root@CentOS6-node1 mysql-5.5.22]# chkconfig mysqld on
设置msyql数据库用户的密码
[root@CentOS6-node1 mysql-5.5.22]# mysqladmin -u root password '666666'
登陆mysql
[root@CentOS6-node1 mysql-5.5.22]# mysql -u root -p
Enter password:
1.查看所有的库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
访问数据库成功!!!
2.查看当前数据库服务的日志文件
mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 107 |
| mysql-bin.000002 | 27338 |
| mysql-bin.000003 | 1031892 |
| mysql-bin.000004 | 245 |
+------------------+-----------+
4 rows in set (0.00 sec)
3.切换库 并 查看该库中的表
mysql> use mysql;
Database changed
mysql> show tables;
5.切换库 并 查看表结构
mysql> use mysql;
Database changed
mysql> describe user;
6.创建新的库bdpn
mysql> create database bdpn;
7.新建表
mysql> use bdpn;
mysql> create table users (user_name char(16) not null, user_passwd char(48));
8.验证表创建成功
mysql> show tables;
mysql> describe users;
9.删除bdpn库中的users表
mysql> drop table bdpn.users;
10.删除bdpn库
mysql> drop database bdpn;
本文出自 “浅笑习惯囿你” 博客,谢绝转载!