- 检查卸载系统自带Mysql及其相关RPM包
[root@localhost ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[root@localhost ~]# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64
[root@localhost ~]# rpm -e –nodeps mysql-libs-5.1.73-3.el6_5.x86_64
- 依次RPM安装这里需要到官网上去下载对应的离线包
rpm -ivh MySQL-server-5.6.36-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.6.36-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.36-1.el6.x86_64.rpm
rpm -ivh MySQL-shared-compat-5.6.36-1.el6.x86_64.rpm
[root@localhost ~]# cd /opt/install/mysql/
[root@localhost mysql]# ls # 查看
MySQL-client-5.6.36-1.el6.x86_64.rpm
MySQL-devel-5.6.36-1.el6.x86_64.rpm
MySQL-server-5.6.36-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.36-1.el6.x86_64.rpm- 查看Mysql配置文件路径
[root@localhost mysql]# which mysql
/usr/bin/mysql
- 复制配置文件
[root@localhost mysql]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
[root@localhost mysql]# cat /etc/my.cnf # 查看内容
- 初始化MySQL及设置密码
[root@localhost mysql]# /usr/bin/mysql_install_db # 数据库初始化
Installing MySQL system tables…2017-07-05 08:49:52 0 [Warning]
…..[root@localhost mysql]# service mysql start # 启动mysq
Starting MySQL.Logging to ‘/var/lib/mysql/localhost.localdomain.err’.
….. [ OK ][root@localhost mysql]# cat /root/.mysql_secret #查看root账号密码
# The random password set for the root user at Wed Jul 5 08:39:25 2017 (local time):bOJlT9YzJpfipSum
[root@localhost mysql]# mysql -u root -p # 登录mysql
Enter password: bOJlT9YzJpfipSum # 输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36mysql> SET PASSWORD = PASSWORD(‘123456’); #修改root密码为123456
Query OK, 0 rows affected (0.01 sec)mysql> exit
Bye
[root@localhost mysql]#
- 允许远程登录
[root@localhost mysql]# mysql -u root -p
Enter password: 123456
Welcome to the MySQL monitor. Commands end with ; or \g.
. . . . . .mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changedmysql> select host,user,password from user;
+———————–+——+——————————————-+
| host | user | password |
+———————–+——+——————————————-+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *58FC8FD7FD9CA737DBE6331A9EEC17E698AF9740 |
| 127.0.0.1 | root | *58FC8FD7FD9CA737DBE6331A9EEC17E698AF9740 |
| ::1 | root | *58FC8FD7FD9CA737DBE6331A9EEC17E698AF9740 |
+———————–+——+——————————————-+
4 rows in set (0.00 sec)mysql> update user set password=password(‘123456′) where user=’root’; # 更新密码
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4 Changed: 3 Warnings: 0mysql> update user set host=’%’ where user=’root’ and host=’localhost’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges; #刷新
Query OK, 0 rows affected (0.00 sec)mysql> exit;
Bye
- 设置Mysql开机启动
[root@localhost mysql]# chkconfig mysql on;
[root@localhost mysql]# chkconfig –list|grep mysql;
本文档详细介绍了在CentOS系统上离线安装MySQL的过程,包括卸载已有的MySQL依赖,下载并安装RPM包,配置MySQL,初始化数据库,设置root密码,允许远程登录以及设置MySQL开机启动。
4549

被折叠的 条评论
为什么被折叠?



