Linux安装MySQL

1、rpm -qa | grep -i mysql  

      检查 whereis mysql
2、将上一步找到的mysql相关的包都删除
rpm -e --nodeps mysql-libs* //*号指代实际包名, 请实际情况输入完整包名
rpm -e mysql-server*(如果有)
rpm -e mysql-client*(如果有)

  检查 rpm -qa | grep -i mysql   whereis mysql  如果没有结果 则下一步
3、检查并删除老版本mysql的开发头文件和库
命令:
rm -fr /usr/lib/mysql
rm -fr /usr/include/mysql
注意:卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除
rm -f /etc/my.cnf
rm -fr /var/lib/mysql
rm -fr /usr/share/mysql
4、安装perl
首先需要配置DNS服务器 vi /etc/resolv.conf
添加一条记录: nameserver 114.114.114.114
yum install perl -y
5、下载numactl-2.0.9-2.el6.x86_64.rpm上传并在其目录中安装
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm
6、下载mysql的四个rpm包上传并安装

         mysql-community-common-5.7.19-1.el6.x86_64.rpm

        mysql-community-libs-5.7.19-1.el6.x86_64.rpm

        mysql-community-client-5.7.19-1.el6.x86_64.rpm

         mysql-community-server-5.7.19-1.el6.x86_64.rpm

安装mysql(有顺序要求)
rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
7、#修改配置文件位置
[root@localhost rpm]# cp  /usr/share/mysql/my-default.cnf   /etc/my.cnf   (如果/etc/my.cnf已经存在,则无需操作)

如果需要更改默认的data文件夹, 请提前更改my.cnf中datadir目录,
socket和pid-file建议还是使用默认的目录/var/lib/mysql
8、修改/etc/my.cnf文件,设置数据库的编码方式:

vi /etc/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
9、如果出现错误,请查看/etc/my.cnf文件中指定的错误log日志的文件
10、service mysqld start
或者:service mysqld restart
11、找到随机密码:
可以查看my.cnf中
/var/log/mysqld.log中有一行:
A temporary password is generated for root@localhost,后面就是随机密码
# mysql -uroot -p"yAe7QGVJ;HlR"使用随机密码登录系统
12、修改默认密码:
set global validate_password_policy=0;
set global validate_password_length=6;
set password for 'root'@'localhost'=password('123456');
搞定
13、设置密码以及查看编码方式
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)

mysql> set password for 'root'@'localhost'=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql>
14、给root设置远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;

放开服务器3306端口

vi /etc/sysconfig/iptables

22端口那一行 yyp 复制到下一行改成 3306  :wq

service iptables restart 

15、chkconfig mysqld on 设置开机启动
默认mysql是开机启动的,如果要设置开启不自启动,则执行
chkconfig mysqld off 

service mysqld status|stop|restart
至此,mysql-5.7安装完毕!

posted @ 2017-10-22 20:25  清风追梦enjoy  阅读(249)  评论(0编辑  收藏  举报