本文由动哒公众号(dongda_5g),QQ群(174353204)提供,欢迎关注获取技术支持,有任何问题群里都会回复。
当我们在云服务器厂商购买好服务器后,可能选择自己安装mysql数据库,下面是本安装过程的详细步骤:
# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
使用上面的命令就直接下载了安装用的yum Repository,然后rpm安装这个源文件,就可以直接yum安装了。具体版本可以通过打开https://dev.mysql.com/downloads/repo/yum/查看。
# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
# yum install mysql-community-server
注意,在百度云服务器时可能报如下错误:
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.21)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libtirpc.so.3(TIRPC_0.3.0)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.20)(64bit)
Error: Package: mysql-community-client-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libc.so.6(GLIBC_2.28)(64bit)
Error: Package: mysql-community-libs-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.21)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libtirpc.so.3()(64bit)
Error: Package: mysql-community-client-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libncurses.so.6()(64bit)
Error: Package: mysql-community-client-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libtinfo.so.6()(64bit)
Error: Package: mysql-community-libs-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libc.so.6(GLIBC_2.28)(64bit)
Error: Package: mysql-community-libs-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.9)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libc.so.6(GLIBC_2.28)(64bit)
Error: Package: mysql-community-client-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.9)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.8)(64bit)
Error: Package: mysql-community-client-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.20)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.11)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.22)(64bit)
Error: Package: mysql-community-libs-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.20)(64bit)
Error: Package: mysql-community-server-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(CXXABI_1.3.9)(64bit)
Error: Package: mysql-community-client-8.0.20-1.el8.x86_64 (mysql80-community)
Requires: libstdc++.so.6(GLIBCXX_3.4.21)(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@instance-8595xzys ~]#
解决的方法比较复杂,我将专列一个专题(详情请看:https://www.jianshu.com/p/2dce53b15204)讲解。
安装之后,我们要设置下root用户的密码,但是,但是,我们必须先重启下,否则登陆不了mysql
# service mysqld restart
5.7的版本有个默认的密码
[root@instance-8595xzys ~]# grep 'temporary password' /var/log/mysqld.log
2019-12-13T00:27:24.624605Z 1 [Note] A temporary password is generated for root@localhost: +rB5yrpjtfKE
[root@instance-8595xzys ~]#
5.7以前的第一次登陆mysql是没有密码的
[root@instance-s3eiwha3 ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.46 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
设置密码,请注意密码必须有字符,大小写,数字组合。
alter user 'root'@'localhost' identified by '$Fyyyzzoqf123';
当然,我们还要授权在任何地方都可以访问,否则,就只能登陆服务器访问。
mysql> use mysql;
mysql> update user set host='%' where user='root';
// 等会再执行下面的命令,否则报错。
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
mysql> flush privileges;
mysql> exit
以上命令跟在5.7的版本不一样,请注意区别。
在5.7的版本中,设置密码可能会报如下错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
然后,我们修改下validate_password_policy参数的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
这样再执行上面的设置密码就可以了。
好了,密码搞定了。
如果是mysql8的话,默认编码格式就是utf8mb4,以下处理可以忽略了。
然后我们再看下字符编码,一般涉及数据迁移的项目,必须要考虑到这点,防患于未然。
mysql> status
--------------
mysql Ver 14.14 Distrib 5.6.46, for Linux (x86_64) using EditLine wrapper
Connection id: 8
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.46 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 31 min 55 sec
Threads: 3 Questions: 56 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.029
--------------
mysql>
可以看到,我们服务器编码是latin1,因此,我们要修改为utf8,以及表名大小写不敏感(lower_case_table_names为1)。编辑/etc/my.cnf
# vi /etc/my.cnf
添加编码设置
collation_server=utf8_general_ci
character_set_server=utf8
lower_case_table_names=1
完整文件如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
collation_server=utf8_general_ci
character_set_server=utf8
lower_case_table_names=1
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
好了,咱们再重启下
# service mysqld restart
再登陆查看下
mysql> status
--------------
mysql Ver 14.14 Distrib 5.6.46, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.46 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 56 sec
Threads: 1 Questions: 7 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.125
--------------
mysql>
现在全是utf8了。
关于mysql更加深入的学习,如mysql主从复制,定时备份等,请看下回分解。
本文由动哒公众号(dongda_5g),QQ群(174353204)提供,欢迎关注获取技术支持,有任何问题群里都会回复。
所有评论(0)