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