1)首先查看这个包是否安装
[root@mysql ~]# rpm -qa ncurses-devel libaio-devel
[root@mysql ~]#
2)如果没有安装请安装
yum install ncurses-devel libaio-devel -y
3)安装cmake编译命令
yum install cmake -y
4)创建mysql虚拟用户不指定家目录
user add mysql-s /sbin/no login -M
5)创建这个目录存放安装包(个人习惯,工作中看公司要求)
mkdir -p /application/tools
6)上传mysql源码包
rz -y #←找到mysql源码包上传上来
7)cd切换到/application/tools准备[解包]
cd /application/tools
8)解包
tar xvf mysql-5.5.32.tar.gz #←解压mysql源码包
9)解包完成后切换到mysql解包的目录
cd mysql-5.5.32
10)开始cmake编译安装,cmake安装mysql参数。
cmake .-DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data\
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii\
-DENABLED_LOCAL_INFILE=ON\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_FEDERATED_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1\
-DWITHOUT_PARTITION_STORAGE_ENGINE=1\
-DWITH_FAST_MUTEXES=1\
-DWITH_ZLIB=bundled\
-DENABLED_LOCAL_INFILE=1\
-DWITH_READLINE=1\
-DWITH_EMBEDDED_SERVER=1\
-DWITH_DEBUG=0
11)cmake编译安装完后make&& make install继续安装
make && make install
12)为mysql数据库创建一个软连接
ln -s /application/mysql-5.5.32/ /application/mysql
13)递归创建目录把这个目录作为mysql存放点,也可用它来开启或关闭服务
mkdir -p /data/{3306,3307}/data
14)切换到根"/"下把data包上传到这里
cd /
15)把data包上传到根"/"下去,是设置3306和3307端口包
rz -y data包
16)解zip包
unzip data.zip
17)查找data目录下的"mysql"找到之后给执行权限
find /data -typef -name "mysql"|xargs chmod +x
18)查看data目录下的"mysql"是否已有执行权限了
find /data -typef -name "mysql"|xargs ls -l
-rwxr-xr-x 1root root 1307 Jul 15 2013/data/3306/mysql
-rwxr-xr-x 1root root 1307 Jul 21 2013/data/3307/mysql
19)给根下"/data/"目录mysql.mysql权限
chown -R mysql.mysql/data/
20)切换此目录
cd /application/mysql/scripts/
21)开始生成3306端口
./mysql_install_db--basedir=/application/mysql/ --datadir=/data/3306/data --user=mysql
22)开始生成3307端口
./mysql_install_db--basedir=/application/mysql/ --datadir=/data/3307/data --user=mysql
23)启动3306方法
/data/3306/mysqlstart
StartingMySQL...
24)启动3307方法
/data/3307/mysqlstart
StartingMySQL...
25)查看是否已有3306或3307端口
netstat -lntup|grep 330
26)把东西拷贝到/usr/local/bin/目录下从而让mysql数据库登录
cp /application/mysql/bin/* /usr/local/bin/
27)无密码登录3306或者登录3307mysql数据库方法
mysql -S /data/3306/mysql.sock #←登录3306实例
mysql -S /data/3307/mysql.sock #←登录3307实例
28)有密码的登录情况,提示工作禁止显示密码出来
登录3306输入密码实例:
mysql -uroot -poldboy123 -S /data/3306/mysql.sock
登录3307输入密码实例:
mysql -uroot -poldboy123 -S /data/3307/mysql.sock
29)放入开机自启动
echo"#mysql multi instances" >>/etc/rc.local #←这个是注释给人看
echo"/data/3306/mysql start" >>/etc/rc.local
echo"/data/3307/mysql start" >>/etc/rc.local
echo"/data/3308/mysql start" >>/etc/rc.local
30)登录mysql多实例
登录3306实例:
mysql -uroot -poldboy123 -S/data/3306/mysql.sock
登录3307实例:
mysql -uroot -poldboy123 -S/data/3307/mysql.sock
2、登录后操作:
mysql> showdatabases;
+--------------------+
| Database |
+--------------------+
|information_schema |
| mysql |
|performance_schema |
| test |
+--------------------+
4 rows in set(0.04 sec)
mysql>
mysql> drop database test; #←默认把test数据库删掉(只删除这一个库)
Query OK, 0 rows affected (0.04sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user |host |
+------+-----------+
| root |127.0.0.1 |
| root |::1 |
| | db02 |
| root |db02 |
| | localhost |
| root |localhost |
+------+-----------+
6 rows in set(0.00 sec)
mysql> drop user ""@db02;
Query OK, 0 rowsaffected (0.01 sec)
mysql> drop user ""@localhost;
Query OK, 0 rowsaffected (0.00 sec)
mysql> drop user "root"@"::1";
Query OK, 0 rowsaffected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user |host |
+------+-----------+
| root |127.0.0.1 |
| root |db02 |
| root |localhost |
+------+-----------+
3 rows in set(0.00 sec)
mysql> drop user "root"@"db02";
Query OK, 0 rowsaffected (0.02 sec)
mysql> select user,host from mysql.user; #←新安装的mysql数据库默认只留下俩个用户
+------+-----------+
| user |host |
+------+-----------+
| root |127.0.0.1 |
| root |localhost |
+------+-----------+
2 rows in set(0.00 sec)