1、下载地址
- https://www.mysql.com/downloads/
- 选择community server
- 点击DOWLOAD
- 选择版本,当前选择的5.6版本
- 点击下载mysql-5.6.38-linux-glibc2.12-i686.tar.gz
- 选择no thanks
2、安装mysql
tar -xvzf mysql-5.6.38-linux-glibc2.12-i686.tar.gz
mv mysql-5.6.38-linux-glibc2.12-i686/ mysql
-
添加系统mysql组和mysql用户:
执行命令:groupadd mysql和useradd -r -g mysql mysql
- 创建mysql数据目录,新目录不存在则创建
数据库数据默认目录datadir=/var/lib/mysql,可通过vim /etc/my.cnf 查看
修改后的目录是 mkdir -p data,没有创建文件夹,有不创建
- 修改目录权限
chown -R mysql:mysql ./
- 初始化数据库
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
- 修改权限为root
[root@localhost mysql]# chown -R root:root .
[root@localhost mysql]# chown -R mysql:mysql data
- 添加启动服务
-
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
- [root@localhost mysql]# service mysql start
本地虚拟机(CentOS6.8)启动MySQL(MySQL5.6.35)服务失败:
[root@VMUest ~]# ll /etc/my.cnf -rw-r--r--. 1 root root 251 Jan 27 05:41 /etc/my.cnf [root@VMUest ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [root@VMUest ~]# ll /etc/ |grep my -rw-r--r--. 1 root root 251 Jan 27 05:41 my.cnf [root@VMUest ~]# mv /etc/my.cnf /etc/my.cnf.bak
- 设置root用户密码
- ./bin/mysqladmin -u root password '123456'
- 遇到的问题
[root@localhost bin]# ./mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- 解决方法
- [root@localhost bin]# ./mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
-
[root@localhost bin]# ./mysql -u root mysql
- mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
- mysql> FLUSH PRIVILEGES;
-
mysql> quit