1、mysql卸载
删除/var/lib/mysql下的文件:
[oracle@ogg mysql]$ su -
Password:
[root@ogg ~]# cd /var/lib/mysql/
[root@ogg mysql]# ls
auto.cnf ib_logfile1 mysql-bin.000001 mysql-bin.000004 mysql-bin.000007 ogg.err test
ibdata1 master-log-bin.index mysql-bin.000002 mysql-bin.000005 mysql-bin.000008 ogg.pid
ib_logfile0 mysql mysql-bin.000003 mysql-bin.000006 mysql-bin.index performance_schema
[root@ogg mysql]# rm -rf *
删除/usr/local/mysql下的文件:
[root@ogg mysql]#cd /usr/local/mysql
[root@ogg mysql]# ls
bin data include lib mysql-5.6.4-m7 README share support-files
COPYING docs INSTALL-BINARY man mysql-test scripts sql-bench
[root@ogg mysql]# rm -rf mysql-5.6.4-m7/
[root@ogg mysql]# rm -rf *
2、mysql源码安装
复制解压后的mysql目录到系统的本地软件目录:
执行命令: cp mysql-5.6.17-linux-glibc2.5-i686 /usr/local/mysql -r注意:目录结尾不要加/
创建mysql用户:
[root@localhost mysql]# useradd mysql
设置mysql用户密码:
[root@localhost mysql]# echo '123456'|passwd --stdin mysql
设置权限:
[root@localhost mysql]# cd /usr/local
[root@localhost local]# chown -R mysql:mysql mysql/
切换到mysql用户
[root@localhost local]# su - mysql
[mysql@localhost ~]$ cd /usr/local/mysql/scripts/
安装mysql数据库:
[mysql@localhost scripts]$ ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
这里可能会报错:scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory。
需要安装perl以及perl-devel.执行命令:yum –y install perl perl-devel
配置文件:
cd /software/mysql-5.6.21/support-files
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql
#
若mysql的安装目录是/usr/local/mysql,则可省略此步
修改文件中的两个变更值
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
datadir=/usr/local/mysql/data
配置环境变量:
vi /etc/profile
export PATH=$MYSQL_HOME/bin:$PATH
保存退出:
source /etc/profile
启动:
[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# chkconfig mysql on
[root@localhost mysql]# service mysql start
Starting MySQL.. SUCCESS!
设置root登录密码:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
登录:
[mysql@localhost ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
</span>
设置登录权限:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.06 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)
mysql>