1. 首先参考 https://zocodev.com/centos7-mysql.html
2. 安装中可能会遇到如下一些问题:
-
Error: Package: akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda) Requires: mariadb-server
- 报错原因 :软件包依赖 mariadb组件
- 解决方案:
-
yum -y remove mariadb-libs
- 然后再运行
-
yum install mysql-community-server
- 原文链接: https://www.cnblogs.com/xuyatao/p/7998057.html
-
/var/log/mysqld.log 中找不到临时密码
- 如果以前安装过mysql,这时的mysqld.log中就不会有temporary password
- 这时就需要删除mysql残留的数据
- rm -rf /var/lib/mysql
- 执行完毕后需要重新启动MySQL服务
- systemctl restart mysqld
- 这时就可以通过上面的命令去查找数据库生成的临时密码了
- 原文链接:https://blog.csdn.net/TTTZZZTTTZZZ/article/details/84102584
插入中文字段问题
参考: https://www.cnblogs.com/livingintruth/p/3433259.html
3. 用C语言编写之前需要下载库, 具体请参考 https://www.cnblogs.com/liudw-0215/p/9593414.html
4. 具体安装日志
boot etc lib media opt root sbin sys usr
[root@localhost /]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# https://zocodev.com/centos7-mysql.html
-bash: https://zocodev.com/centos7-mysql.html: No such file or directory
[root@localhost /]#
[root@localhost /]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data.
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=52 time=17.7 ms
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=52 time=16.3 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 16.316/17.046/17.776/0.730 ms
[root@localhost /]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
--2019-08-28 20:31:47-- https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [following]
--2019-08-28 20:31:49-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.79.160.128
Connecting to repo.mysql.com (repo.mysql.com)|23.79.160.128|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-11.noarch.rpm’
100%[===========================================================>] 25,680 67.5KB/s in 0.4s
2019-08-28 20:31:50 (67.5 KB/s) - ‘mysql57-community-release-el7-11.noarch.rpm’ saved [25680/25680]
[root@localhost /]# yum localinstall mysql57-community-release-el7-11.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch
Marking mysql57-community-release-el7-11.noarch.rpm as an update to mysql57-community-release-el7-7.noarch
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-7 will be updated
---> Package mysql57-community-release.noarch 0:el7-11 will be an update
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
mysql-connectors-community/x86_64 | 2.5 kB 00:00:00
mysql-tools-community/x86_64 | 2.5 kB 00:00:00
mysql57-community/x86_64 | 2.5 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
Dependencies Resolved
=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Updating:
mysql57-community-release noarch el7-11 /mysql57-community-release-el7-11.noarch 31 k
Transaction Summary
=====================================================================================================
Upgrade 1 Package
Total size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : mysql57-community-release-el7-11.noarch 1/2
Cleanup : mysql57-community-release-el7-7.noarch 2/2
Verifying : mysql57-community-release-el7-11.noarch 1/2
Verifying : mysql57-community-release-el7-7.noarch 2/2
Updated:
mysql57-community-release.noarch 0:el7-11
Complete!
[root@localhost /]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 95
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 364
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled
[root@localhost /]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: centos.ustc.edu.cn
Package mysql-community-server-5.7.27-1.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log
2019-08-28T02:14:11.170094Z 1 [Note] A temporary password is generated for root@localhost: 3gwM(ClHU%ed
[root@localhost /]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
... Failed! Error: Your password does not satisfy the current policy requirements
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
... Failed! Error: Your password does not satisfy the current policy requirements
New password:
Sorry, you can't use an empty password here.
New password:
Re-enter new password:
... Failed! Error: Your password does not satisfy the current policy requirements
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) :
... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
[root@localhost /]# su
[root@localhost /]# su centos
[centos@localhost /]$ ls
bin etc lib64 mysql57-community-release-el7-11.noarch.rpm root srv usr
boot home media opt run sys var
dev lib mnt proc sbin tmp
[centos@localhost /]$ rm mysql57-community-release-el7-11.noarch.rpm
rm: remove write-protected regular file ‘mysql57-community-release-el7-11.noarch.rpm’? n
[centos@localhost /]$
[centos@localhost /]$ ls
bin etc lib64 mysql57-community-release-el7-11.noarch.rpm root srv usr
boot home media opt run sys var
dev lib mnt proc sbin tmp
[centos@localhost /]$ create user zocodev_user@'localhost' IDENTIFIED BY 'ABCabc123@@';
bash: create: command not found...
[centos@localhost /]$ service mysqld start
Redirecting to /bin/systemctl start mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: centos
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Failed to start mysqld.service: Access denied
See system logs and 'systemctl status mysqld.service' for details.
[centos@localhost /]$ su
Password:
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@localhost /]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@localhost /]# su centos
[centos@localhost /]$
[centos@localhost /]$
[centos@localhost /]$ service mysqld start
Redirecting to /bin/systemctl start mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: centos
Password:
==== AUTHENTICATION COMPLETE ===
[centos@localhost /]$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[centos@localhost /]$
[centos@localhost /]$
[centos@localhost /]$
[centos@localhost /]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 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> help
For information about MySQL products and services, visit:
http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
For server side help, type 'help contents'
mysql> show databases
-> show databases
->
-> show databases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show databases
show databases' at line 2
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.04 sec)
mysql> create user zocodev_user@'localhost' IDENTIFIED BY 'ABCabc123@@';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> grant all privileges on zocodev.* to zocodev_user@localhost identified by 'ABCabc123@@';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[centos@localhost /]$
[centos@localhost /]$ apt-get install libmysqlclient15-dev
bash: apt-get: command not found...
[centos@localhost /]$ yum instll libmysqlclient15-dev
Loaded plugins: fastestmirror, langpacks
No such command: instll. Please use /usr/bin/yum --help
[centos@localhost /]$ su
Password:
[root@localhost /]# apt-get install libmysqlclient15-dev
bash: apt-get: command not found...
[root@localhost /]# wget http://www.rpmfind.net/linux/dag/redhat/el7/en/x86_64/dag/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
--2019-08-28 21:15:01-- http://www.rpmfind.net/linux/dag/redhat/el7/en/x86_64/dag/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
Resolving www.rpmfind.net (www.rpmfind.net)... 195.220.108.108
Connecting to www.rpmfind.net (www.rpmfind.net)|195.220.108.108|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12520 (12K) [application/x-rpm]
Saving to: ‘rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm’
100%[==================================================>] 12,520 6.59KB/s in 1.9s
2019-08-28 21:15:04 (6.59 KB/s) - ‘rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm’ saved [12520/12520]
[root@localhost /]# yum install apt
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: centos.ustc.edu.cn
No package apt available.
Error: Nothing to do
[root@localhost /]# yum localinstll rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
No such command: localinstll. Please use /usr/bin/yum --help
[root@localhost /]# yum localinstall rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm: rpmforge-release-0.5.3-1.el7.rf.x86_64
Marking rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package rpmforge-release.x86_64 0:0.5.3-1.el7.rf will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
rpmforge-release x86_64 0.5.3-1.el7.rf /rpmforge-release-0.5.3-1.el7.rf.x86_64 13 k
Transaction Summary
============================================================================================
Install 1 Package
Total size: 13 k
Installed size: 13 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : rpmforge-release-0.5.3-1.el7.rf.x86_64 1/1
Verifying : rpmforge-release-0.5.3-1.el7.rf.x86_64 1/1
Installed:
rpmforge-release.x86_64 0:0.5.3-1.el7.rf
Complete!
[root@localhost /]# apt-get update
bash: apt-get: command not found...
[root@localhost /]# sudo apt-get update
sudo: apt-get: command not found
[root@localhost /]# rpm rpm -i rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm^C
[root@localhost /]# rpm -i rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
package rpmforge-release-0.5.3-1.el7.rf.x86_64 is already installed
[root@localhost /]# yum install apt
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* rpmforge: mirror1.hs-esslingen.de
* updates: centos.ustc.edu.cn
rpmforge | 1.9 kB 00:00:00
rpmforge/primary_db | 125 kB 00:00:12
No package apt available.
Error: Nothing to do
[root@localhost /]# sudo apt-get update
sudo: apt-get: command not found
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# apt-get
bash: apt-get: command not found...
[root@localhost /]# ls
bin media run
boot mnt sbin
dev mysql57-community-release-el7-11.noarch.rpm srv
etc opt sys
home proc tmp
lib root usr
lib64 rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm var
[root@localhost /]# cat /proc/version
Linux version 3.10.0-957.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Thu Nov 8 23:39:32 UTC 2018
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# ls
bin media run
boot mnt sbin
dev mysql57-community-release-el7-11.noarch.rpm srv
etc opt sys
home proc tmp
lib root usr
lib64 rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm var
[root@localhost /]# rm -f mysql57-community-release-el7-11.noarch.rpm
[root@localhost /]# ls
bin etc lib64 opt rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm srv usr
boot home media proc run sys var
dev lib mnt root sbin tmp
[root@localhost /]# yum install mysql-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* rpmforge: mirror.fairway.ne.jp
* updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.27-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
mysql-community-devel x86_64 5.7.27-1.el7 mysql57-community 3.7 M
Transaction Summary
============================================================================================
Install 1 Package
Total download size: 3.7 M
Installed size: 22 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-devel-5.7.27-1.el7.x86_64.rpm | 3.7 MB 00:00:10
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-devel-5.7.27-1.el7.x86_64 1/1
Verifying : mysql-community-devel-5.7.27-1.el7.x86_64 1/1
Installed:
mysql-community-devel.x86_64 0:5.7.27-1.el7
Complete!
[root@localhost /]# cd /home/
centos/ exchange/ mysql/ program/
[root@localhost /]# cd /home/exchange/
[root@localhost exchange]# ls
goodthreadpoll myservices test
[root@localhost exchange]# mkdir database
[root@localhost exchange]# cd database/
[root@localhost database]# ls
[root@localhost database]#
[root@localhost database]#
[root@localhost database]# ls
[root@localhost database]# cd ..
[root@localhost exchange]# ls
database goodthreadpoll myservices test test.c
[root@localhost exchange]# mv test.c database/
[root@localhost exchange]# cd database/
[root@localhost database]# ls
test.c
[root@localhost database]# mv test.c sql.c
[root@localhost database]# ls
sql.c
[root@localhost database]# gcc sql.c -o sql -I/usr/include/mysql -L/usr/lib64/mysql -lmysqlclient
[root@localhost database]# ls
sql sql.c
[root@localhost database]#