一、安装 mysql:
[root@localhost ~]# yum -y install gcc glibc libaio libstdc++ libstdc ncurses-libs
[root@localhost ~]# yum install gcc gcc-c++
[root@localhost ~]# yum install ncurses ncurses-devel
[root@localhost ~]# mkdir -p /usr/local/src
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# rz+软件名
[root@localhost src]# tar xf mysql-5.7.17-linux-glibc2.5-i686.tar.gz
[root@localhost src]# useradd mysql -s /sbin/nologin -M
[root@localhost src]# mv mysql-5.7.17-linux-glibc2.5-i686 /usr/local/mysql
[root@localhost src]# cd /usr/local/mysql
[root@localhost mysql]# ln -s mysql-5.7.17-linux-glibc2.5-i686 mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# bin/mysqld --initialize --user=mysql #生成的密码要记住:root@localhost: 1daeiqUjJL_q
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# mkdir -p /usr/local/mysql/data
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# bin/mysqld_safe --user=mysql &
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# chkconfig --level 2345 mysql on
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# service mysqld start
Starting MySQL.. SUCCESS!
[root@localhost mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
二、添加环境变量:
[root@localhost mysql]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
# source /etc/profile
补充:通过配置my.cnf mysql选项socket文件位置解决
[root@localhost mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost mysql]# vim /etc/my.cnf
在最后增加即可:
[mysql]
no-auto-rehash
socket = /var/lib/mysql/mysql.sock
[root@localhost mysql]# service mysqld start
Starting MySQL.. SUCCESS!
[root@localhost mysql]# mysql -uroot -p
三、访问数据库,用安装时给的随机密码进行第一次登录:
[root@localhost mysql]# mysql -uroot -p
四、怎么修改 mysql 数据库的随机密码
mysql> set password for 'root'@localhost = password ('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 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>