1、 创建mysql安装目录:
[root@localhost ~]#mkdir –pv /usr/local/mysql/
2、 创建数据存放目录:
[root@localhost ~]#mkdir –pv /data/mysql/
3、 创建用户和用户组,并赋予数据存放目录权限:
[root@localhost ~]#groupadd mysql
[root@localhost ~]#useradd –r –g mysqlmysql
[root@localhost ~]#chown –R mysql:mysql/data/mysql
4、 安装编译源码需要的包:
[root@localhost ~]#yum –y install makegcc-c++ cmake bison-devel ncurses-devel perl
5、 编译mysql:
[root@localhost ~]#cd /usr/src
[root@localhost ~]#tar zxvfmysql-5.6.25.tar.gz
[root@localhost ~]#cd mysql-5.6.25
[root@localhost ~]#cmake .–DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
6、编译时间比较长,耐心等待,之后安装:
[root@localhost ~]#make && makeinstall
7、 修改/etc/profile文件,为mysql添加PATH环境变量:
[root@localhost ~]#exportPATH=$PATH:/usr/local/mysql/bin
[root@localhost ~]#vim /etc/profile末行添加:exportPATH=$PATH:/usr/local/mysql/bin
8、 使配置文件生效:
[root@localhost ~]#source /etc/profile
9、 将mysql的配置文件拷贝到/etc目录下:
[root@localhost ~]#cd/usr/local/mysql/support-files/
[root@localhost ~]#cp my-default.cnf/etc/my.cnf
[root@localhost ~]#cp mysql.server/etc/init.d/mysqld
[root@localhost ~]#chmod 755/etc/init.d/mysqld
10、 修改/etc/my.cnf文件,末行添加如下语句:
[root@localhost ~]#vim /etc/my.cnf
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
character-set-server = utf8
collation-server = utf8_general_ci
character-set_client-handshake = false
11、 编辑文件/etc/init.d/mysqld文件,末行添加如下语句:
[root@localhost ~]#vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
12、 进入/usr/local/mysql/scripts/生成mysql用户数据库和表文件:
[root@localhost ~]#cd/usr/local/mysql/scripts/
[root@localhost ~]#./mysql_install_db–user=mysql –basedir=/usr/loca/mysql –datadir=/data/mysql/
13、 添加服务并启动:
[root@localhost ~]#chkconfig –add mysqld
[root@localhost ~]#chkconfig mysqld on
[root@localhost ~]#chkconfig –list mysqld
14、 启动数据库:
[root@localhost ~]#service mysqld start
15、 设置root帐户密码:
[root@localhost ~]#mysqladmin –urootpassword “123456”
16、 登录mysql数据库:
[root@localhost ~]#mysql –uroot –p
17、 删除用于本机匿名登录的空密码帐号:
Mysql>use mysql
Mysql>delete from user wherepassword=””;
Mysql>flush privileges;
18、 更改root的密码:
Mysql>update user setpassword=password(‘123456’) where user=’root’;
Mysql>commit;
Mysql>flush privileges;
19、 创建用户mysql:
Mysql>create user ‘mysql’ identified by‘123456’;
20、 给mysql用户赋权限:
Mysql>GRANT ALL PRIVILEGES ON mysql.*TO mysql@‘%’;
卸载mysql:
1、 关闭目前的mysql服务:#servicemysqld stop
2、 确保已经正常关闭:#ps–ef | grep mysql
3、 查询mysql的安装情况:#rpm–qa | grep mysql
4、 将列出来的卸载:#rpm–e –nodeps
5、 如果报有多个,则用项—allmatches将其全部卸掉。