uname -a
首先查看系统是32位还是64位操作系统,然后下载相应的mysql版本
https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
创建mysql用户:
[root@localhost mysql]# useradd mysql
设置权限:
[root@localhost mysql]# cd /usr/local
[root@localhost local]# chown -R mysql:mysql mysql/
切换到mysql用户
[root@localhost local]# su - mysql
[mysql@localhost ~]$ cd /usr/local/mysql/scripts/
安装
yum –y install perl perl-devel
[mysql@localhost scripts]$ ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
配置文件
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql #若mysql的安装目录是/usr/local/mysql,则可省略此步
修改文件中的两个变更值
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
配置环境变量
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
保存退出
source /etc/profile
启动
[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# chkconfig mysql on
[root@localhost mysql]# service mysql start
Starting MySQL.. SUCCESS!
设置root登录密码
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
登录
[mysql@localhost ~]$ mysql -uroot -p
Enter password:
设置登录权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.06 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)