官網命令如下:
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysql_ssl_rsa_setup
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
一:下載並解壓
mysql官網下載連接:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz這個可以直接下載。如果不行的話去https://dev.mysql.com/downloads/mysql/ 這個網站找。下載好後通過tar -zxvf MySQL文件名字解壓。其中z代表顯示文件具有gzip屬性,x代表解壓,v代表顯示所有過程,f代表檔案名字。其中,f必須在名字參數的最後。f後面加需要解壓的文件名字。比如: tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz。然後通過mv命令修改下文件夾名字,因爲太長了,比如改爲mysql5.7。
二:安裝連接初始化
2.1仍在第一步的目錄位置,執行以下命令。
ln -s /usr/local/mysql5.7 mysql
其中/usr/local/mysql5.7 是修改後的文件夾目錄。
2.2 進入mysql5.7文件夾;
cd mysql5.7
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server
官網安裝的鏈接如下:
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
也可以設置到系統啓動。
其中可能有幾個坑和錯誤。
1:mysql5.7中,user表中沒有password字段!!!假如想更新密碼必須這樣:update mysql.user set authentication_string=password('root') where user='root';
2:默認的,通過mysqld啓動後,mysql是需要密碼的。但是又不知道密碼。只能通過安全模式啓動。safe_mysqld --skip-grant-tables &。但是還有個問題,如果是登陸的root賬戶。這樣是啓動不了的。必須使用非root賬戶啓動mysqld。比如用mysql賬號。
safe_mysqld --user=mysql --skip-grant-tables & 上面這個就能啓動。然後通過錯誤1的更新下密碼。然後就可以登陸了。如果,你在執行的最上面的命令後能夠直接登陸mysql就不需要再執行這2步了,就直接修改root密碼了。
3.成功登陸mysql後必須先修改下密碼,因爲第一次。必須設置密碼!。
flush privileges; 刷新
創建用戶:create user 'test'@'%' identified by '123456'; 即可遠程登陸。
假如忘記了mysql密碼,請查看http://www.jb51.net/article/100766.htm。這裏面可以解決。我用的是方法2。
如果錯誤:[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
:https://www.cnblogs.com/abclife/p/5052997.html如果錯誤:
bin/mysqld: error while loading shared libraries: libnuma.so.1: centos7安裝mysql5.7
按照mysql出現這個錯誤:bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
這是缺少numactl。
這個時候如果是Centos就yum -y install numactl
就可以解決這個問題了.
ubuntu的就sudo apt-get install numactl
就可以解決這個問題了。