一、下载MySQL
- cd /usr/local
- wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- tar xvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
二、创建MySQL用户和组
- groupadd mysql
- useradd -r -g mysql mysql -d /usr/local/mysql
- passwd mysql
三、修改目录权限
- chown -R mysql:mysql /usr/local/mysql
四、安装数据库
- su mysql
- /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
- exit
五、复制配置文件并添加系统服务
- cd /usr/local/mysql/support-files
- cp my-default.cnf /etc/my.cnf
- cp mysql.server /etc/init.d/mysql
- chkconfig mysql on
六、配置环境变量
- vim /etc/profile
- 在文件末尾加 export MYSQL_HOME="/usr/local/mysql",export PATH="$PATH:$MYSQL_HOME/bin"
- 保存退出,然后执行 . /etc/profile
七、启动MySQL
- service mysql start
八、设置root密码
- mysqladmin -u root password '123456'
九、设置默认端口
- vim /etc/my.cnf
- [mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
server_id=1
socket=/tmp/mysql.sock
十、允许外部链接访问
- mysql -u root -p
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
- FLUSH PRIVILEGES;