| #!/bin/sh |
| |
| |
| |
| t_Log "Running $0 - python can retrieve mysql-server version information." |
| |
| if [ "$centos_ver" -ge 8 ] ; then |
| PYTHON=python3 |
| else |
| PYTHON=python |
| fi |
| |
| |
| |
| if [ "$centos_ver" -ge 7 ] ; then |
| my_packages="mariadb mariadb-server nc" |
| mysql_service="mariadb" |
| elif [ "$centos_ver" = "5" ] ;then |
| my_packages="mysql mysql-server nc mysql55-mysql-server" |
| mysql_service="mysqld" |
| else |
| my_packages="mysql mysql-server nc" |
| mysql_service="mysqld" |
| fi |
| |
| t_InstallPackage ${my_packages} |
| t_ServiceControl ${mysql_service} start >/dev/null 2>&1 |
| |
| |
| if [ "$centos_ver" -ge 8 ] ; then |
| t_InstallPackage python3-PyMySQL |
| importcomponent="pymysql" |
| else |
| t_InstallPackage MySQL-python |
| importcomponent="MySQLdb" |
| fi |
| |
| |
| SCRIPT='/var/tmp/test.py' |
| |
| cat >$SCRIPT <<EOF |
| import $importcomponent |
| |
| conn = $importcomponent.connect (unix_socket="/var/lib/mysql/mysql.sock", |
| user = "", |
| passwd = "", |
| db = "") |
| cursor = conn.cursor () |
| cursor.execute ("SELECT VERSION()") |
| row = cursor.fetchone () |
| print ("server version:", row[0]) |
| cursor.close () |
| conn.close () |
| EOF |
| |
| |
| $PYTHON $SCRIPT |grep -q 'server version' |
| |
| t_CheckExitStatus $? |
| |
| |
| /bin/rm $SCRIPT |