How to install mysql 5.5 or 5.6 on ubuntu 16.04 xenial

Connect to your server.

  1. Uninstall any existing version of MySQL
    sudo rm /var/lib/mysql/ -R
  2. Delete the MySQL profile
    sudo rm /etc/mysql/ -R
  3. Automatically uninstall mysql
    sudo apt-get autoremove mysql* --purge
    sudo apt-get remove apparmor
  4. Download version 5.5.51 from MySQL site
    wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
  5. Add mysql user group
    sudo groupadd mysql
  6. Add mysql (not the current user) to mysql user group
    sudo useradd -g mysql mysql
  7. Extract  to /usr/local
    sudo tar -xvf mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
  8. Create mysql folder in /usr/local by moving the untarred folder
    cd /usr/local
    sudo mv mysql-5.5.49-linux2.6-x86_64 mysql
  9. Set mysql directory owner and user group
    cd mysql
    sudo chown -R mysql:mysql *
  10. Install the required lib package (works with 5.6 as well)
    sudo apt-get install libaio1
  11. Execute mysql installation script
    sudo scripts/mysql_install_db --user=mysql
  12. Set mysql directory owner from outside the mysql directory
    sudo chown -R root .
  13. Set data directory owner from inside mysql directory
    sudo chown -R mysql data
  14. Copy the mysql configuration file
    sudo cp support-files/my-medium.cnf /etc/my.cnf (mysql 5.5)
    sudo cp support-files/my-default.cnf /etc/my.cnf (mysl 5.6)
  15. Start mysql
    sudo bin/mysqld_safe --user=mysql &
    sudo cp support-files/mysql.server /etc/init.d/mysql.server
  16. Initialize root user password
    sudo bin/mysqladmin -u root password '[your new password]'
  17. Add mysql path to the system
    sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
  18. Reboot!
  19. Start mysql server
    sudo /etc/init.d/mysql.server start
    
  20. Stop mysql server
    sudo /etc/init.d/mysql.server stop
  21. Check status of mysql
    sudo /etc/init.d/mysql.server status
  22. Enable myql on startup
    sudo update-rc.d -f mysql.server defaults

    Disable mysql on startup (Optional)

    sudo update-rc.d -f mysql.server remove
  23. REBOOT!
  24. Now directly use the command below to start mysql if it hasn’t
    sudo service start mysql -u root -p

    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    ./bin/mysqladmin -u root password 'new-password'
    ./bin/mysqladmin -u root -h VM-0-14-ubuntu password 'new-password'

    Alternatively you can run:
    ./bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default.  This is
    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:
    cd . ; ./bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl
    cd ./mysql-test ; perl mysql-test-run.pl

    Please report any problems at http://bugs.mysql.com/

  25.  

     

    Can't connect to local MySQL server through socket '/usr/local/mysql/data/mysql.sock' (111)

     

    启动的原理是,

    /home/ubuntu/mysql-5.5.56-linux-glibc2.5-i686/support-files/mysql.server这个文件中定义了my.cnf文件,my.cnf文件中定义了一切

    修改my.cnf文件:

  26. 在/etc/my.cnf文件中添加如下内容,并重启mysqls服务,即可解决mysql,mysqldump,mysqladmin的“Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'”问题:

    [mysqld]
    datadir=/storage/db/mysql
    socket=/storage/db/mysql/mysql.sock

    [mysql]
    socket=/storage/db/mysql/mysql.sock

    [client]
    socket=/storage/db/mysql/mysql.sock

    [mysqldump]
    socket=/storage/db/mysql/mysql.sock

    [mysqladmin]
    socket=/storage/db/mysql/mysql.sock

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值