1、下载tar.gz,解压到/usr/local/mysql 2、设置环境变量 vim /etc/profile export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH source /etc/profile 3、初始化设置 mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data (会出错,可将 安装目录/mysql/data下的文件全部删除) 4、将mysql设置成系统服务 cd /usr/local/mysql cp support-files/mysql.server /etc/init.d/mysqld chmod a+x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on chkconfig --list | grep mysqld 5、编辑配置文件 vim /etc/my.cnf ########################################### [mysqld] datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock [mysqld_safe] log-error=/usr/local/mysql/logs/mysqld.log pid-file=/usr/local/mysql/pids/mysqld.pid symbolic-links=0 [client] default-character-set=utf8 socket=/usr/local/mysql/mysql.sock [mysql] default-character-set=utf8 socket=/usr/local/mysql/mysql.sock !includedir /etc/my.cnf.d ############################################ 7、创建相关文件和目录 mkdir -p /var/lib/mysql/ mkdir -p /etc/my.cnf.d/ touch /usr/local/mysql/logs/mysqld.log touch /usr/local/mysql/pids/mysqld.pid chown mysql.mysql -R /usr/local/mysql/ 8、开启服务&查看服务状态 service mysqld start service mysqld status 无密码的状态可以直接以mysql命令进入mysql的交互界面 mysql 9、给mysql设置root密码 mysqladmin -u root password “root” 使用密码登录 mysql -uroot –p