Linux安装MySQL

  1. 默认安装在/usr/local/mysql目录里,也可以安装在其他位置,官网下载地址:
  • 64bit
  • 32bit
  1. 创建文件夹,解压并移动到MySQL目录
[sudo] mkdir /usr/local/mysql
tar -xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz/* /usr/local/mysql/
  1. 创建data目录
mkdir /usr/local/mysql/data
  1. 创建mysql用户和修改权限
groupadd mysql
chown -R mysql:mysql /usr/local/mysql/  
  1. 初始化数据
[root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/  
2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize  
2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:  
2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead  
2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)  
2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)  
  1. 复制配置文件到 /etc/my.cnf
cp -a ./support-files/my-default.cnf /etc/my.cnf  #选择y
  1. mysql的服务脚本放到系统服务中
cp -a ./support-files/mysql.server /etc/init.d/mysqld

修改/etc/my.cnf文件

# These are commonly set, remove the # and set as required.  
basedir = /usr/local/mysql  
datadir = /usr/local/mysql/data  # 修改data目录
port = 3306  
# server_id = .....  
socket = /tmp/mysql.sock  
character-set-server = utf8  
# Remove leading # to set options mainly useful for reporting servers.  
# The server defaults are faster for transactions and fast SELECTs.  
# Adjust sizes as needed, experiment to find the optimal values.  
# join_buffer_size = 128M  
# sort_buffer_size = 2M  
# read_rnd_buffer_size = 2M   
  1. 启动mysql
service mysqld start
ps -ef  #查看是启动
  1. 查看初始化自动生成的密码:
cat /root/.mysql_secret  #记住并复制下来,等会登陆mysql需要
  1. 进入mysql
bin/mysql -uroot -p  #把刚刚复制的密码粘贴上来
  1. 登录后重置root密码
mysql> SET PASSWORD  FOR 'root'@localhost = PASSWORD('123456');Query OK, 0 rows affected, 1 warning (0.00 sec)

12 . 开机启动

chkconfig mysql on
chkconfig --list|grep mysql

ntsysv

你可能感兴趣的:(Linux安装MySQL)